Skip to content

Instantly share code, notes, and snippets.

View kuangbeibei's full-sized avatar
🎯
Focusing

Beth kuangbeibei

🎯
Focusing
  • Basepair
  • Australia
  • 21:44 (UTC -12:00)
View GitHub Profile
@gaearon
gaearon / uselayouteffect-ssr.md
Last active May 2, 2024 13:42
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() {