Jump to content
Search Community

useGSAP adds callbacks but doesn't kill the previous ones

this_is_giulio
Moderator Tag

Recommended Posts

this_is_giulio
Posted

Hello everyone again,
 

I have a React component with a `counter` state defined using `useState`.

I use `useGSAP` to create a timeline with `scrollTrigger` and update the component’s state in the `onUpdate` callback.

 

The problem is that the “old” `onUpdate` callbacks are not being cleared and continue to run.

I created a repo to illustrate the issue quickly. https://stackblitz.com/edit/react-sfv36uzm?file=src%2FApp.js

 

Where am I going wrong?

this_is_giulio
Posted

Anyone? :D

Posted

Hi,

 

Sorry for the delay, this one slipped through the cracks 🙏

 

I think your approach might be a bit convoluted, this seems simpler and easier, plus you don't have to set the counter as a dependency and the setCounter method is not called on every update (pretty wasteful IMHO):

https://stackblitz.com/edit/react-ckyyevug?file=src%2FApp.js

 

Hopefully this helps

Happy Twening!

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