ReactIntermediate#hooks#refs

What is useRef used for?

useRef holds a mutable value in a box that survives re-renders without causing them. It is used for DOM access, storing timers or previous values, and holding non-render data.

Example
const inputRef = useRef(null);
useEffect(() => inputRef.current?.focus(), []);
return <input ref={inputRef} />;

Related Questions

1
ReactAdvanced#hooks#performance

Difference between useMemo and useCallback?

Open
2
ReactAdvanced#performance

What is React.memo?

Open
3
ReactIntermediate#hooks#context

What is useContext and when do you use it?

Open