Call hooks only at the top level of a component or another hook, never inside a condition, loop, or nested callback, and only from React functions. The reason is that React stores hook state as an ordered list on the fiber and matches each call to a slot by call order, not by name. Change the order between renders and every hook after that point reads the wrong slot.
Why interviewers ask this
The rules are easy to recite, so the interviewer is really asking for the why. A candidate who explains the ordered slot list understands the implementation and will reason correctly about custom hooks, conditional logic and lint suppressions. It also opens a natural follow up about how you structure code when you only conditionally need something, which is where weaker candidates start writing hooks inside if blocks.
How to structure your answer
- State the two rules plainly and briefly.
- Explain the call order slot mechanism as the reason.
- Describe what actually breaks when the order changes.
- Say how you handle conditional needs without breaking the rules.
Example answer
Two rules: hooks go at the top level, and they only get called from a component or another hook. The reason is the implementation. React does not know the names of your hooks, it keeps a list on the fiber and moves a cursor through it as your function runs, so the first useState call gets slot one, the second gets slot two, and so on. If you wrap a hook in an if, then on some renders the cursor lands one position off, and every hook after that reads the previous hook's state. You get bizarre failures where a boolean turns into a function. When I do need something conditionally, I always call the hook and make the hook itself do nothing, for example passing an enabled flag to a query hook, or pushing the branch up a level so the two paths are separate components. I keep the eslint rules on and treat a suppression as something that needs a comment explaining exactly why.
Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.
See how it worksFollow-up questions to expect
- How would you handle a hook that you only sometimes need?
- What does the eslint plugin actually catch, and what does it miss?
- How would you write a custom hook that composes two other hooks?
Related react developer questions
Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.
Predict my questions