Q16: What are the two core Rules of Hooks in React?

  1. Call hooks only at the top level of components/custom hooks (never inside loops, conditions, or nested functions). 2. Call hooks only from React function components or custom hooks.
Key Takeaways
  • Never call hooks conditionally or inside loops to guarantee hook invocation order.
  • Only call hooks from React function components or custom hooks.
Knowledge Check

Why must hooks only be called at the top level of a function component?