AceDevHub
Beginner React Interview QuestionsBeginnerConcept

React · Question 26

What are the Rules of Hooks?

Direct answer

Most Hooks must be called at the top level of a function component or custom Hook so React sees them in a consistent order on every render.

  • Top level: do not call ordinary Hooks inside loops, conditions, nested callbacks, or after conditional returns.
  • React functions: call Hooks from function components or custom Hooks, not ordinary JavaScript functions or class components.
  • Static order: React relies on stable Hook call ordering to associate state with each call.

The React use() API has special calling rules and is an exception to some ordinary Hook restrictions, so avoid overgeneralizing the rule to every function beginning with use.