The useState Setter Stability Guarantee
You'll learn why React's useState setter functions never cause unnecessary re-renders, making them safe to pass through Context without useMemo.
The Stability Promise
When you call useState, React returns two things: the current state value and a setter function. Here's React's guarantee: that setter function has a stable identity that never changes between renders. It's the same function reference every single time, for the lifetime of that component instance.
This is different from the state value itself, which changes. The setter? Rock solid.
Why This Matters for Context
Remember those Context performance traps where {{ user, setUser }} caused all consumers to re-render? The object was the problem—it's new every render. But the setter function alone? Not guilty.
const [count, setCount] = useState(0);
// ❌ This object changes every render
<CountContext.Provider value={{ count, setCount }}>
// ✅ setCount is stable - no useMemo needed!
<DispatchContext.Provider value={setCount}>
When you split Context and pass only the setter to a dispatch Context, you don't need to wrap it in useMemo. React already guarantees it won't change.
The Practical Impact
This is why the "split Context" pattern works so well. You can create a write-only dispatch Context that provides just setCount, and consumers of that Context will never re-render when count changes—only when the component itself needs to for other reasons.
Key Takeaway: React's useState setter functions have stable identity across renders, so they're safe to pass through Context without useMemo—unlike objects or inline values that change every time.