tezvyn:

useEffect: Syncing React with the Outside World

Source: react.devintermediate

useEffect synchronizes your component with systems outside React's control, acting as a bridge to the browser or network. It's for data fetching or subscriptions.

useEffect synchronizes your component with systems outside React's control, like the browser DOM, network requests, or timers. It's the designated escape hatch for "side effects"—code that interacts with the world outside of rendering. Use it for fetching data when a component mounts or setting up a WebSocket connection. The main footgun is the dependency array: omitting it runs the effect on every render, while an empty array (`[]`) runs it only once. Forgetting a dependency leads to stale data.

Read the original → react.dev

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

useEffect: Syncing React with the Outside World · Tezvyn