What are hooks, and why don't we call them conditionally?
Answer out loud or in your head first, then compare.
Answer
Hooks are React functions that let a component use state, effects and refs, among other things. Examples are useState, useEffect and useRef. A custom hook lets you extract repeated logic.
We call regular hooks in a fixed order at the top level of a component or custom hook. That's how React assigns state to the right call. If I call useState inside an if once and skip it the next time, the order changes. When behaviour should be conditional, I usually put the condition inside the effect or extract a component. Special APIs such as use have their own rules.
Why it matters: A practical foundation of working with React, whatever the level of the role.
Possible follow-ups: What belongs in a custom hook rather than in the component?
How did it go? Be honest — “Not yet” puts the question on your review list.
Related questions
- Why do we need hooks in ReactJS? — React
Further reading
- React: Synchronizing with Effects(opens in a new tab)Docs; accessed 22.10.2026. What Effects are for, cleanup, and protecting against stale results.