Course contentsShow
← React
Lesson 711 of 2,39619. useRefFree lesson

Refs Are Not Reactive

React does not track changes to ref.current; reading it in render will not subscribe to updates or cause re-renders.

Refs Are Not Reactive

What you'll learn: Why changing ref.current doesn't trigger re-renders or updates in your component.

The Core Distinction

When you modify ref.current, React doesn't "see" the change. Unlike state (from useState), refs are invisible to React's rendering system. Changing a ref value won't cause your component to re-render, and reading ref.current during render won't subscribe your component to future updates.

This is by design — refs are an "escape hatch" for values you need to persist but don't want to trigger the React rendering cycle.

Why This Matters

function BrokenCounter() {
  const countRef = useRef(0);

  function increment() {
    countRef.current = countRef.current + 1;
    // Component won't re-render! The screen won't update!
  }

  return (
    <div>
      <p>Count: {countRef.current}</p>
      <button onClick={increment}>Increment</button>
    </div>
  );
}

In this example, clicking the button does update countRef.current in memory, but the component never re-renders, so the displayed count stays frozen at 0.

The Analogy

Think of state as a whiteboard that React watches — any change triggers a refresh of what's displayed. A ref is like a sticky note in your pocket — you can read and write to it anytime, but React never checks it. It won't know when you've changed it, and won't update the screen.

When Refs Are Right

Use refs for values that shouldn't affect what's rendered: DOM nodes, timers, previous values, flags for async operations. If the value needs to appear on screen or control what renders, use useState instead.

Key Takeaway: Changing ref.current is a silent mutation — React doesn't track it, won't re-render for it, and reading it doesn't create a reactive subscription.