Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
frontend ruleP0stack specificStack: react
reacthookscorrectness
Never call a hook inside a function invoked conditionally in render
Calling a hook (useTranslation, useState) inside a plain render-helper function that is rendered conditionally changes the hook count between renders and throws 'Rendered fewer hooks than expected'. Make it a component or move the hook to the top level.
PR: frontpage-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | const RenderClearBtn = ({ handleClick }) => { const [t] = useTranslation(); /*...*/ }; |
| 2 | return <div>{value && RenderClearBtn({ handleClick })}</div>; // hook count varies |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const ClearBtn = ({ handleClick }) => { const [t] = useTranslation(); /*...*/ }; |
| 2 | return <div>{value && <ClearBtn handleClick={handleClick} />}</div>; |
Explanation (EN)
Objašnjenje (HR)