Jump to content
Search Community

Resetting an animation in React is not setting to inital state

TAAT test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I have a simple animation -

1. Lines get highlighted one after the other on click on a button.

2. Clicking on button again, while the animation is running, should de-highlight the lines to original state.

 

However, on setting the timeline progress of animation to 0, all the values get reset, but the last one modified continues to remain in same state. 

 

To reproduce, click the button, and after a couple lines have highlighted, click the button again. 

 

Code Sandbox : https://codesandbox.io/s/inspiring-gates-poozb

See the Pen by s (@s) on CodePen

Link to comment
Share on other sites

Set the state yourself in your return function.

setHighlightA(false);
setHighlightB(false);
setHighlightC(false);
setHighlightD(false);

 

And trying to animate a boolean is strange. It's converting them to strings. Something a little simpler.

 

timeLineLength.to(animationData, 1, { onStart() { setHighlightA(true); } })
timeLineLength.to(animationData, 1, { onStart() { setHighlightB(true); } })
timeLineLength.to(animationData, 1, { onStart() { setHighlightC(true); } })
timeLineLength.to(animationData, 1, { onStart() { setHighlightD(true); } })

 

Link to comment
Share on other sites

37 minutes ago, OSUblake said:

Set the state yourself in your return function.


setHighlightA(false);
setHighlightB(false);
setHighlightC(false);
setHighlightD(false);

 

And trying to animate a boolean is strange. It's converting them to strings. Something a little simpler.

 


timeLineLength.to(animationData, 1, { onStart() { setHighlightA(true); } })
timeLineLength.to(animationData, 1, { onStart() { setHighlightB(true); } })
timeLineLength.to(animationData, 1, { onStart() { setHighlightC(true); } })
timeLineLength.to(animationData, 1, { onStart() { setHighlightD(true); } })

 

Thanks, I did try setting the Highlights manually and typecasting the boolean values, but didn't give the expected behavior. 

 

I have realized that on updating the react-dom version, it does behave the way it is expected. I have raised an issue with React as well : https://github.com/facebook/react/issues/17112

 

In case someone has some insights, please do let know. 

 

 

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...