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 ruleP2universalStack: React
reacthooksreuseclean-code
Use a toggle hook for simple boolean state
For on/off UI state, reach for an existing useToggle/useToggleState hook instead of a raw useState boolean with manual setters.
PR: hegnar-components · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetsx
| 1 | const [isVisible, setIsVisible] = useState<boolean>(false); |
| 2 | // manual setIsVisible(true)/setIsVisible(false) everywhere |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | const [isVisible, toggleVisible] = useToggleState(false); |
Explanation (EN)
Objašnjenje (HR)