React · Junior · Question 28 of 75
Which rule of hooks is broken?
function Profile({ id }) {
if (!id) return null;
const [data, setData] = useState(null);
// ...
}- 1Hooks can't be used in components that accept props
- ✓Correct answer: The hook is called after a conditional
return- the hook order changes - 3Nothing is broken: an early
returnwith hooks is allowed
Explanation
React matches state to hooks by their call order. If a hook isn't called during some render (because of an early return, a condition or a loop), the order breaks. Call hooks at the top level, before any conditional exits.