Tsallaka zuwa abun ciki
Justice Tech School

Rules of Hooks

Call hooks only at the top level of components or custom hooks.

Example
function Bad({ ok }) {
  // if (ok) { const [a] = useState(1); } // not allowed
  const [a] = useState(1);
  return <p>{a}</p>;
}

Exercise

Top level.

Call hooks at the  level

Quiz Test

Can hooks be called inside loops?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.