Jump to content
Search Community

Read react state when animation completes

badtant test
Moderator Tag

Recommended Posts

Hey badtant and welcome to the GreenSock forums! This is just a React question, not a GSAP one, but I'll help anyway.

 

The issue is that you didn't pass in the state to your useEffect so it essentially creates a new variable called count. If you want to access your state, you need to pass it inside of the second parameter where you currently have an empty array. But then it will run it again when the state changes, which isn't what you want. This is a good article on the subject.

 

Why not just use a class instead?

 

As for your actual GSAP code, don't use translateX. Just use x. And you don't need to include the px or make the values strings:

gsap.fromTo(boxRef.current, { 
  x: 0 
}, {
  x: 500,
  duration: 5,
  onComplete: complete
});

 

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.
×
×
  • Create New...