Identifying Reusable Logic
You'll learn how to spot patterns in your components that signal an opportunity for a custom hook.
The Pattern Recognition Game
Now that you understand what custom hooks are, the next skill is recognizing when to create one. Custom hooks emerge from repeated patterns—when you notice yourself writing the same useState, useEffect, or other hook combinations across multiple components, that's your cue.
Look for these telltale signs:
1. Copy-Pasted Hook Sequences
If you're copying the same 3-5 lines of hooks from one component to another with minor tweaks, that's prime custom hook territory.
2. Stateful Logic + Side Effects Together
When you see useState paired with useEffect to manage a specific behavior (like fetching data, tracking window size, or managing form validation), that combination is begging to be extracted.
3. Multiple Components Doing "The Same Thing"
A UserProfile component tracking online status, a ChatWidget doing the same thing, and a FriendList also checking if users are online—three copies of identical logic.
Think of It Like Recipes
If you notice you're mixing the same ingredients (hooks) in the same order across different dishes (components), it's time to write that recipe down as a reusable function. You wouldn't hand-write pancake instructions every time you make breakfast—you'd follow the recipe.
The key is behavioral repetition, not just visual similarity. The logic might look slightly different in each component, but if it's solving the same problem (tracking form state, syncing with localStorage, debouncing input), that's your signal.
Key Takeaway: Custom hooks emerge from patterns—look for repeated combinations of hooks that solve the same problem across multiple components, even if the details differ slightly.