Skip to content
Advertisement

GSAP Animations(TweenMax) not triggering in React,

I cannot figure out for the life me what how to get this Gsap animations to work. I’m still learning react but I was able to get everything to work properly in a standard project using html, css, and javascipt but i wanted to try and recreate the effect in React. There’s much more code, it’ll compile but the animations are kicking in. The error on the console says nothing is wrong and VSCode says nothing is wrong so i’m at a loss. Seems like it should be a simple fix though.

JavaScript

However in a basic HTML it works when I write it as follows…

JavaScript

I also tried rewriting everything to follow the modern best practises.

Advertisement

Answer

In order to use gsap in react, make sure you have followed these steps:

  1. Create and run basic react app.
JavaScript
  1. Install gsap in the react app using:
JavaScript
  1. Import the gsap module into the app and use it with the useEffect hook.
JavaScript

Here, React will re-run the useEffect() on every render. If you want to avoid that, add empty dependency array.

Like this:

JavaScript

Check this documentation for more info: greensock.com/react

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement