DemonDisguise Posted June 19 Posted June 19 (edited) I just started using gsap with typescript and have been getting error, how do i fix, this is the code: useGSAP(() => { gsap.to(box3.current, { rotation: "+=360" }); }, null); here I am trying to force an animation to trigger on every render here i am getting error near null saying: Argument of type 'null' is not assignable to parameter of type 'useGSAPConfig | unknown[] | undefined'.ts(2345) Edited June 19 by DemonDisguise
Rodrigo Posted June 19 Posted June 19 Hi @DemonDisguise and welcome to the GSAP Forums! In this case is better to use the config object to pass a dependency, which would re-run the code on every state/prop update. Is quite weird to have no control over what exactly should trigger the re-render. In that particular case, a parent component re-render will also trigger the re-render and create the new animation, which could be unexpected for the user and cause a bad UX. If you want to add to the rotation on a user interaction, like a click or mouse enter/leave is better to use state for that. Finally without a minimal demo, it's very difficult to troubleshoot; the issue could be caused by CSS, markup, a third party library, a 3rd party script, etc. Would you please provide a very simple CodePen or Stackblitz that illustrates the issue? Please don't include your whole project. Just some colored <div> elements and the GSAP code is best. See if you can recreate the issue with as few dependencies as possible. Start minimal and then incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, at least we have a reduced test case which greatly increases your chances of getting a relevant answer. See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen. that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo: Using a framework/library like React, Vue, Next, etc.? CodePen isn't always ideal for these tools, so here are some Stackblitz starter templates that you can fork and import GSAP as shown in the Install Helper in our Learning Center : React (please read this article!) Next Svelte Sveltekit Vue Nuxt Please share the StackBlitz link directly to the file in question (where you've put the GSAP code) so we don't need to hunt through all the files. Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. ✅
DemonDisguise Posted June 20 Author Posted June 20 https://stackblitz.com/edit/stackblitz-starters-6bs4omd3?file=app%2Fpage.tsx this is the demo well the useGSAP was not rendering when i used null as the dependency in my laptop. But in stackblitz it is running the animation two times. Please check the div with "Every render" on it. i am use box3 as the ref for it in useGSAP
Solution Rodrigo Posted June 20 Solution Posted June 20 Hi, The behavior is completely expected actually. You're updating the count state property and then using a timer that updates a different state property, hence you have two state properties updated by the same event, one in a synchronous way the other in an asynchronous way (soto speak). Each state update triggers a component re-render which triggers the animation. So two state updates, to renders and two animations, makes complete sense ✅
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now