Skip to main content

Refs visual mental model

Refs persist between renders, but changing them does not request another render.

One ref object survives many renders
Render 1
Render 2
Render 3
ref object

.current can change imperatively without scheduling React rendering.

State vs ref​

Choose by whether React must render the change
ReactiveState

Persists between renders. Setter schedules future rendering. Use it when JSX depends on the value.

ImperativeRef

Persists between renders. .current mutates immediately. Use it when React does not need to render the value.

Where should this value live?
Changes visible UI?State
Timer / AbortController / external instance?Ref
DOM node for focus or measurement?Ref
Derived from props/state?Calculate during render
Shared reactive application data?State architecture, not a hidden ref store

DOM refs​

DOM ref ownership
React component

renders an element with ref

DOM element

input · dialog · canvas · video · measured element

Imperative operation

focus · scroll · measure · play · integrate third-party widget

Why refs are escape hatches​

Healthy vs unhealthy ref usage
Healthy

Keep a narrow imperative handle React does not need for rendering.

Unhealthy

Store UI/domain state in .current just to avoid re-renders.

If the interface depends on a value, hiding that value in a ref breaks React's normal reactive data flow.

Imperative handles​

Expose the smallest imperative surface
Parent

needs one imperative capability

Child ref contract

focus() · open() · reset() — only what is intentionally exposed

Internal DOM / implementation

stays encapsulated inside the child

Continue with useRef and DOM Refs and Imperative Handles for complete examples and edge cases.