Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next.js 13 useRef is not a function/failed to load #1

Closed
carlosmca44 opened this issue May 19, 2023 · 1 comment
Closed

Next.js 13 useRef is not a function/failed to load #1

carlosmca44 opened this issue May 19, 2023 · 1 comment

Comments

@carlosmca44
Copy link

the server console shows the following error

- error node_modules/next-reveal/dist/cjs/components/RevealWrapper.js (8:34) @ RevealWrapper
- error TypeError: (0 , react_1.useRef) is not a function
    at stringify (<anonymous>)
digest: "4115955940"
null

keep in mind that it is a project where nextjs 13 and reactjs 18 are used

@ritmillio
Copy link
Owner

ritmillio commented May 19, 2023

Hi @carlosmca44,

Thank you for reaching out with this issue. In the new React 18 architecture, which includes server-side rendering (SSR), using useRef to reference elements from the DOM is no longer possible. To address this, you need to specify 'use client' at the top of the component or page where you intend to use next-reveal in Next.js 13.

I know that using 'use client' means losing the benefits of SSR. In order to work around this limitation, I recommend creating a separate component outside of the pages directory specifically for loading your animations. This way, you can maintain SSR for the rest of the page. This is a dirty quick fix, but until I find a better approach, I suggest trying this workaround. Alternatively, if you have any ideas or suggestions, please feel free to contribute to the lib.

@ritmillio ritmillio pinned this issue May 19, 2023
@ritmillio ritmillio changed the title failed to load Next.js 13 useRef is not a function/failed to load May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants