greensock / react

Tools for using GSAP in React, like useGSAP() which is a drop-in replacement for useLayoutEffect()/useEffect()
251 stars 7 forks source link

TypeError reading useRef #10

Closed studiosi closed 3 months ago

studiosi commented 4 months ago

Hello,

I am just on a normal installation of NextJS in which I have been using GSAP for a while.

When trying to use useGSAP for automatic cleanup, I get this error

TypeError: Cannot read properties of null (reading 'useRef')

which is generated on this line

https://github.com/greensock/react/blob/b00905d1e00ce0b873e6c4b0cb09770254836b55/src/index.js#L32

I wonder if this is a problem with the usage of useRef or something that I am doing wrong.

jackdoyle commented 4 months ago

Hm, it's very difficult to troubleshoot blind, but it kinda sounds like you don't have React installed or something. The useRef is being imported at the top from "react"...and the error indicates that's null. There must be some issue with your environment(?)

Maybe try spinning up the simplest possible React project and do a basic useGSAP() in that and see if it works. If you can recreate the problem there, send us the repo or something so we can have some way of seeing the problem in context. It certainly sounds like a problem in your environment or build tool or something.

iDVB commented 3 months ago

We saw this when attempting to run on react@rc (v19).

s-pyadyshev commented 3 months ago

same issue with react 19 beta, react, vite

studiosi commented 3 months ago

@jackdoyle I have to say that yes, I have React installed (it is a working NextJS installation), I had already GSAP working (doing all the work manually) and that this is a type error.

Thanks for checking it out. I will try to create a minimal reproduction as soon as I can.

studiosi commented 3 months ago

I am closing this because I can't seem to be able to reproduce the issue. In case someone wants to check a minimal example of using GSAP inside of a Typescript Next.js app with TailwindCSS, I created this example while I was trying to make this error happen.

https://github.com/studiosi/gsap-react-example

seismicsix commented 2 months ago

For anyone who had the issue with react RC19...

You can add this to your package.json file to force the gsap plugin to reference the correct version of react.

"overrides": { "@gsap/react": { "react": YOUR_REACT_RC_VERSION } }

hope this helps :-)

paulrrdiaz commented 1 month ago

Getting the same issue. @seismicsix could you give more details about

"overrides": { "@gsap/react": { "react": YOUR_REACT_RC_VERSION } } ?

I've tried

"overrides": {
      "@gsap/react": {
            "react": "18.2.0"
      }
 }

but no luck, thanks in advance

thesportslms commented 1 month ago

Getting the same issue. @seismicsix could you give more details about

"overrides": { "@gsap/react": { "react": YOUR_REACT_RC_VERSION } } ?

I've tried

"overrides": {
      "@gsap/react": {
            "react": "18.2.0"
      }
 }

but no luck, thanks in advance

YOUR_REACT_RC_VERSION = should reference the react version 19 you're trying to install; so update;

        "react": "18.2.0"

to something like

        "react": "19.0.0-rc-??????-????"