Skip to content
React·Intermediate·Coding·1 min read

What is useEffect for?

Short interview answer

An effect synchronizes a rendered component with an external system such as a subscription, network connection, timer, imperative widget, or browser API. It is not the default place for values that can be derived during render or logic caused directly by an event.

Example

JSX
useEffect(() => {  const conn = createConnection(roomId);  conn.connect();  return () => conn.disconnect(); // undo exactly what was set up}, [roomId]);

Key takeaway

Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.

← Back to React effects

Related questions