Skip to catalogue

rules of hooks

React Hooks follow rules about where they can be called.

Use this when A component calls useState or useEffect conditionally.

without the term

“I added an early return and now React says 'rendered more hooks than during the previous render'. Can you fix it so it works for both cases?”

with the term · How do you ask a model for rules of hooks?

Fix this component’s Hook call order. Keep the rules-of-hooks check enabled and test both sides of the conditional behavior.

XBlueskyLinkedIn

What is rules of hooks?

React matches Hook state to calls by their order, so state and effect Hooks must run in the same order on every render: at the top level of a component or custom Hook, never inside a condition or loop.

Why does rules of hooks matter when vibe coding?

An added branch can change which Hook state corresponds to each call.

How do you do rules of hooks?

Keep stateful Hooks in components or custom Hooks at valid call sites and retain the lint checks.

What goes wrong with rules of hooks?

Applying an oversimplified rule to APIs with documented exceptions instead of checking the API contract.

adjacent

reviewed

report a correction