Skip to content

fix(useLocalStorage): replace useLayoutEffect with useIsomorphicLayoutEffect#2702

Open
DISCONECTED-png wants to merge 1 commit intostreamich:masterfrom
DISCONECTED-png:fix/useLocalStorage-useIsomorphicLayoutEffect
Open

fix(useLocalStorage): replace useLayoutEffect with useIsomorphicLayoutEffect#2702
DISCONECTED-png wants to merge 1 commit intostreamich:masterfrom
DISCONECTED-png:fix/useLocalStorage-useIsomorphicLayoutEffect

Conversation

@DISCONECTED-png
Copy link
Copy Markdown

Problem

useLocalStorage imports and uses useLayoutEffect directly from React (line 1 & 56),
which causes this warning in SSR environments:

Warning: useLayoutEffect does nothing on the server because its effect cannot
be encoded into the server renderer's output format.

Fix

Replaced useLayoutEffect with useIsomorphicLayoutEffect — the utility already
exported by this library — which automatically falls back to useEffect on the
server and uses useLayoutEffect in the browser.

This is the same pattern already used in createGlobalState.ts (fixed in #956).

Relates to: #956

…tEffect

useLayoutEffect causes a React warning when rendered server-side because
it does not exist in SSR environments. The library already exports
useIsomorphicLayoutEffect which automatically falls back to useEffect
on the server — the same pattern used in createGlobalState.

Relates to: streamich#956
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

Successfully merging this pull request may close these issues.

1 participant