What does useEffect do?

React hooks and effects · Freshers

Model answer

useEffect runs code after React has rendered and updated the screen. It is for synchronising with things outside React: fetching data, subscribing to events, timers, or changing the document title.

You pass a function and a dependency array. The effect re-runs when a dependency changes. It can return a cleanup function that React runs before the next effect and when the component unmounts.

Learn this topic

React useEffect Explained: Side Effects, Dependencies and Cleanup in the course React.js Full Course: Beginner to Advanced.

Sign in to add your own answer.

More questions