The Signal: When Logic is Repeated Across Components
You'll learn: How to spot the telltale patterns that scream "extract this into a custom hook" before copy-paste becomes your enemy.
The Repeated Logic Problem
Imagine you're building a recipe app. In three different components—RecipeCard, IngredientList, and CookingTimer—you find yourself writing nearly identical useState and useEffect blocks to fetch data from an API. You change variable names, adjust the URL slightly, but the structure is the same: initial loading state, fetch call, error handling, cleanup.
This is your signal.
What to Look For
The classic indicators that logic deserves extraction:
- Copy-pasting
useState+useEffectpairs across components with minor tweaks - Similar patterns for form inputs, toggle states, or timers appearing in multiple places
- Boilerplate that feels tedious to rewrite each time
- Bug fixes needing the same change in 4+ locations
Think of it like recognizing a recipe you've cooked before. If you're following the same steps (set state, run effect, cleanup) but just swapping ingredients (different URLs, different state names), you're repeating yourself.
Not Every Repetition Counts
A single useState call appearing in two components? Probably fine. But when you see useState, useEffect, and cleanup logic traveling together like a pack, that's the pattern worth extracting.
The goal isn't to eliminate all repetition—it's to capture reusable behavior that would otherwise drift apart when maintained separately.
Key Takeaway: When you catch yourself copying blocks of hook calls with the same logical flow across components, that's your cue to extract a custom hook—even before the third copy.