0
Challenge · 22Hooks & Effects

useEffect

Coreused in ~95% of apps

Most code belongs in render or in an event handler. useEffect is the escape hatch for the leftover: keeping your component in sync with something OUTSIDE React — a server connection, a subscription, a timer, the document title. Reach for it last, not first.

Core idea. useEffect lets a component synchronize with an external system after it renders: the effect body starts syncing, and the function it returns stops syncing (cleanup). React runs it after the screen is painted, and re-runs it whenever a value in its dependency array changes.
Playground, this isn't a screenshot
the component on screen
component not mounted
nothing on screen, no connection
lifecycle timeline (top → bottom)
Press Mount and watch render → effect fire.
dependency roomId:

Change the room while mounted: React re-renders, runs cleanup for the old room, then the effect for the new one.

↑ play a little first, then dig in