Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Rick May

GSAP and useState doing weird things

Recommended Posts

  @GreenSock helped me with a question a while back (linked at bottom) that helped me a lot.  I've had some time to go back to this project and I'm now having a different problem when I setState .  The gsap gets out of whack and I cannot figure out why.  I'm hoping someone can help me.  :)

 

Codesandbox:

https://codesandbox.io/s/gsap-and-usestate-icy6b

 

If you visit the watered down version of my problem above..  Press play, stop and shift right.  It works as expected.  However, as soon as you click the Set State button, everything gets screwy with the animation.  Does anyone know what I can do about this?  I'm stumped.

 

Thanks,

Rick

 

original thread: 

 

 

Link to post
Share on other sites

First, an animation/timeline/tween is not a state. Use a ref instead. A ref is just like using this in a class component. 

 

When you set state in hooks, you lose everything that wasn't saved in a ref/state. 

https://codesandbox.io/s/gsap-and-usestate-4prg6?file=/src/child1.js

 

I think that is really confusing, which is why I prefer using classes for gsap animations. 

  • Like 6
  • Thanks 1
Link to post
Share on other sites

Thanks @OSUblake.  The timeline in a state had me confused.  But, it was working until I added a feature (unrelated to setting a state, but doing so in the sandbox was the quickest way to demonstrate) to my project a couple of days ago.  I'll take the TL out of a state and go from there. 

 

Thanks for the help.  :D

 

  • Like 1
Link to post
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.

×