useEffect lets a component run side effects — like fetching data, subscriptions, or manually changing the DOM — after rendering, separate from the core rendering logic.
Rendering in React should ideally be a "pure" calculation of what the UI looks like for the current state and props. Side effects — anything that reaches outside that calculation, like an API call or setting up an event listener — belong in useEffect instead.
useEffect(() => {
document.title = `You clicked {'{'}count{'}'} times`;
}, [count]);
This effect runs after every render where count has changed since the last render. The array at the end (called the dependency array) controls when the effect re-runs.
[]: the effect runs once, after the first render only[count]: the effect runs after the first render, and again any time a listed value changesAn effect can return a cleanup function, which React runs before the component unmounts or before the effect runs again — commonly used to remove event listeners or cancel subscriptions that the effect set up, preventing memory leaks.
Last reviewed: September 2026