Skip to content

Instantly share code, notes, and snippets.

View kuangbeibei's full-sized avatar
:octocat:

Beth kuangbeibei

:octocat:
  • Australia
  • 01:07 (UTC -12:00)
View GitHub Profile
@gaearon
gaearon / uselayouteffect-ssr.md
Last active November 26, 2025 07:31
useLayoutEffect and server rendering

If you use server rendering, keep in mind that neither useLayoutEffect nor useEffect can run until the JavaScript is downloaded.

You might see a warning if you try to useLayoutEffect on the server. Here's two common ways to fix it.

Option 1: Convert to useEffect

If this effect isn't important for first render (i.e. if the UI still looks valid before it runs), then useEffect instead.

function MyComponent() {