Jump to content
Search Community

Getting this error while working with gsap in typescript of null

DemonDisguise
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

DemonDisguise
Posted (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 by DemonDisguise
Rodrigo
Posted

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 : 

 

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. 

  • Solution
Rodrigo
Posted

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

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