Write a Custom Hook
Talk it through out loud with your AI coach.
The problem
- medium
- Pro
Three components each track the window's width with their own state, effect and resize listener, copied and pasted. Explain how you'd extract a custom hook for this, and what rules hooks must follow.
What a strong answer covers
- What a custom hook is and how it's named.
- Setting up and tearing down the listener inside it.
- Whether components using the same hook share state.
- The rules all hooks must follow, and why.
Common mistake: Expecting a custom hook to share one piece of state between every component that calls it.
Knowing this is half of it. Saying it clearly out loud is the part the coach helps you practise.
Practise it out loud