useEffect

Synchronizes a component with an external system after render.

Since React 16.8 Spec ↗

Syntax

useEffect(setup, dependencies?)

Parameters

NameTypeRequiredDescription
setup function Yes Effect function run after commit; may return a cleanup function.
dependencies array No Reactive values the effect depends on; the effect re-runs when any change.

Returns

undefined — useEffect returns nothing.

Examples

useEffect(() => {
  const id = setInterval(tick, 1000);
  return () => clearInterval(id);
}, []);
useEffect(() => {
  document.title = `Count: ${count}`;
}, [count]);

Notes

The cleanup runs before the next effect and on unmount. Omitting the dependency array runs the effect after every render; an empty array runs it once after mount. Include every reactive value used inside. Effects run twice in development under Strict Mode to surface missing cleanup. Do not use effects for pure data transformation.

See also