When NOT to Extract Custom Hooks
What you'll learn: How to recognize when extracting logic into a custom hook adds unnecessary complexity rather than value.
The Extraction Trap
You've learned to build custom hooks like useToggle, useLocalStorage, and useDebounce. It's tempting to extract everything into reusable hooks. But extraction has a cost: indirection, cognitive load, and maintenance overhead.
Three Signs You Shouldn't Extract
1. Logic Appears Only Once
If you're using state and effects in a single component with no plans to reuse elsewhere, keep it inline. A useProductDetails hook used in only one place is premature abstraction.
2. Too Specific to Be Reusable
Logic tightly coupled to one feature—like "fetch user cart items and calculate shipping based on zip code"—won't generalize well. Forcing it into a hook creates a false sense of reusability.
3. Simpler Inline
If extracting adds more lines, more files, and more mental hoops to understand the flow, you've made the code harder to read. A straightforward useState + useEffect combo in your component might be clearer than jumping to a custom hook definition elsewhere.
Wait for Patterns to Emerge
The best custom hooks emerge from repeated patterns. When you copy-paste similar logic the second or third time, then extract. Don't predict future reuse—respond to actual duplication.
Analogy
Think of custom hooks like kitchen gadgets. A garlic press is useful if you mince garlic daily. But buying one for a single recipe next month? You'll clutter your drawer and waste time searching for it instead of just using a knife.
Key Takeaway: Extract custom hooks when you have clear, repeated patterns—not for single-use or overly specific logic. Keep it simple until reuse actually emerges.