Rules Hub
Code Ruleset
← 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
reactstateredundancy
Remove redundant state that duplicates another flag
If two pieces of state always hold the same value, drop one; carrying both invites them drifting out of sync.
PR: hegnar-forum-web · org-mining-3rd-2026-06Created: Jun 18, 2026
Bad example
Old codets
| 1 | const [isTruncatable, setIsTruncatable] = useState(false); |
| 2 | const [shouldClamp, setShouldClamp] = useState(false); // always == isTruncatable |
Explanation (EN)
Two mutable copies of the same fact can diverge and require unnecessary synchronization.
Objašnjenje (HR)
Good example
New codets
| 1 | const [isTruncatable, setIsTruncatable] = useState(false); |
| 2 | // derive clamp from isTruncatable && !isExpanded |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Trace all reads and writes of the two values; derive one only if it is a pure function of current state/props and never changes independently.
Exceptions / Tradeoffs (EN)
Keep a user-editable draft, history snapshot, animation phase or external synchronization state when it has a separate lifecycle.