Advanced Patterns (useReducer, useRef, useImperativeHandle)
Title says advanced patterns, so depth must include misuse boundaries, debugging cost, and API contract implications across components.
Quick Navigation: Pattern Fit by Problem Type • Trade-offs and Hidden Costs • Edge Cases and Interview Takeaway
Quick Decision Guide
Advanced hook patterns map to different problem classes.
- useReducer: explicit transition logic - useRef: mutable non-render state and DOM handles - useImperativeHandle: narrow imperative contracts across boundaries
Interview signal: justify choice by invariants, not preference.
Pattern Fit by Problem Type
🔥 Insight
Pick primitive by invariant, not by popularity.
useReducer
Use when transitions need explicit, auditable state changes.
useRef
Use for mutable values that should not trigger re-render.
useImperativeHandle
Use when parent needs a controlled imperative capability (focus, reset, scroll).
Edge Cases and Interview Takeaway
Edge Cases
🎯 Interview Takeaway
Strong answer: choose tool by invariant, explain misuse risk, and define a narrow contract.
Rules of Hooks (and why)
These rules follow from React's render model: