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

useLayoutEffect does nothing on the server in useClickAway hook #295

Open
garciafdezpatricia opened this issue Apr 11, 2024 · 0 comments
Open

Comments

@garciafdezpatricia
Copy link

Hello,

I'm using the useClickAway hook from the @uidotdev/usehooks library in my Next.js application. When I run my application in development mode, I'm seeing the following warning in my console:

Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer’s output format. This will lead to a mismatch between the initial, non-hydrated UI and the intended UI. To avoid this, useLayoutEffect should only be used in components that render exclusively on the client.

I've traced this warning back to the useClickAway hook, which appears to be using useLayoutEffect. While this isn't causing any issues in the functionality of my application, the warning is a bit concerning as it suggests there could be a mismatch between the server-rendered and client-rendered output.

I understand that useLayoutEffect is necessary for certain use cases, but in a server-rendered environment like Next.js, it can cause warnings and potential hydration issues. Would it be possible to replace useLayoutEffect with useEffect in the useClickAway hook, or provide an alternative hook for server-rendered environments?

Thank you for your time and for providing this very useful library,
Patricia

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

1 participant