An effect is code that runs because the component rendered, not because the user did something. Its job is to keep the component synchronized with an external system while it's on screen: a chat connection, a browser event subscription, a non-React widget, document.title. Logic caused by one interaction (submit, buy) belongs in its event handler; values computed from props and state belong in render.
When it runs. Never during rendering. React renders, commits the DOM changes, runs layout effects, and only then runs useEffect setups, children before parents. The effect sees the committed DOM and the props and state of the render that created it.
Which moment after the commit depends on what caused the update:
- Not a discrete input (initial
root.render, a timer, a network response): React schedules effects in a separate task, so the browser can paint between the commit and the effect. That's the documented "usually after paint". - A discrete input such as a click or key press: React runs the effects at the end of the same task, before paint, so their result is observable straight away.
flushSync, or a layout effect that sets state: React flushes pending effects synchronously too.
So "after paint" is a tendency, not a promise: visual work that must not flicker goes in useLayoutEffect.
How often. With no dependency array, after every commit of the component; with [], only after it mounts; with [a, b], after commits where a or b changed by Object.is. Before re-running, React calls the previous cleanup.
Not a lifecycle method. Read an effect as "keep this in sync with these values", not "run on mount". Strict Mode tests exactly that in development with an extra setup and cleanup. Effects never run during server rendering, which makes them the place for browser-only APIs.