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 ruleP2stack specificStack: react
reacthooksencapsulationapi-design
Keep a custom hook's state inside the hook
A custom hook should own and return derived state from inputs, not push state ownership back onto every caller.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetsx
| 1 | const [isAdmin, setIsAdmin] = useState(false); |
| 2 | useIsAdmin(deletedBy, userId, setIsAdmin); // caller owns the state |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | const isAdmin = useIsAdmin(deletedBy, userId); // hook owns and returns the state |
Explanation (EN)
Objašnjenje (HR)