Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
useRef gives a mutable box whose current value persists between renders without triggering a re-render; it is used for DOM elements and values like timer ids.
useRef returns the same object { current } on every render. Changing ref.current does not cause a re-render, unlike calling a state setter. Common uses are accessing a DOM node, for example to focus an input after a button click, and storing values that do not affect what is shown, such as an interval id or the previous value of a prop. Anything that should appear on screen belongs in state, because changing a ref will not update the UI.