[BUG] useLayoutEffect warning when rendering serverside
See original GitHub issueThe change in #195 introduces useLayoutEffect
to the the useViewportScroll
(and the new useElementScroll
) hook, that causes a React warning when rendering serverside.
See CodeSandbox
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. See https://fb.me/react-uselayouteffect-ssr for common fixes.
A common fix is to create a useIsomorphicLayoutEffect
that selects the right effect for the env.
const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect : useEffect
function Comp() {
useIsomorphicLayoutEffect(() => {
// ...
})
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:14
- Comments:9 (1 by maintainers)
Top Results From Across the Web
How to fix the "Warning: useLayoutEffect does nothing on the ...
Heres the full error: Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's ...
Read more >useLayoutEffect and SSR - Medium
useLayoutEffect logs a nasty warning in server-side rendering. You can hack around this warning by conditionally using useEffect in server ...
Read more >useLayoutEffect and the warning on SSR - Eight Bites
Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format.
Read more >Module Constraints - Remix
Browser-only code - Remix renders on the server so your modules can't have ... set in a useLayoutEffect in your elements and you...
Read more >React useLayoutEffect vs. useEffect with examples
Compare the useEffect and useLayoutEffect Hooks in React, ... passed to useEffect will run after the render is committed to the screen”.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m using NextJs 12 and Framer 6.2.6 and am seeing this error.
I solved this problem with: