Jump to content
GreenSock

DeDX

MotionPath not working with React

Go to solution Solved by GreenSock,

Recommended Posts

Hello!
I want to move the purple block along the path I've draw in the SVG. 

This is one section of my website which uses gsap all over the page. Rest of the page can be easily selected using the ref but when I use MotionPath, It throws Invalid scope and Target not found error.

 

Here's the codesandbox: https://codesandbox.io/s/gsap-motionpath-react-bkscsf?file=/src/App.js

Thank You!

Link to comment
Share on other sites

  • Solution

I'm definitely not a React guy, but I think the problem may be that you're trying to reference ".App" before it even exists. You could use the ref instead because GSAP's selector is smart enough to check for .current on the object you pass in:

 

// BAD
const appRef = useRef(null);
const el = gsap.utils.selector(".App");

// GOOD
const appRef = useRef(null);
const el = gsap.utils.selector(appRef);

Does that help? 

  • Thanks 1
Link to comment
Share on other sites

I tried that and it wasn't working. 🙃 Paging @OSUblake for his shift in the React mines

  • Thanks 1
Link to comment
Share on other sites

  • 2 weeks later...

The solution was to initialize gsap.selector inside useLayoutEffect and to use a completely different timeline for motionpath instead of chaining it with tweens. Thank you cassie and greensock for help!

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×