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

What belongs in a ref?

Short interview answer

A ref holds a mutable value that persists across renders without triggering a render when changed. It fits DOM nodes, imperative handles, timer ids, or latest values used outside rendering. Visible UI data belongs in state.

Example

JSX
const intervalId = useRef(null);useEffect(() => {  intervalId.current = setInterval(tick, 1000);  return () => clearInterval(intervalId.current);}, []);

Key takeaway

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

← Back to React hooks

Related questions