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 ruleP1universalStack: react
statecorrectnessdata-modelingreact
Model mutually exclusive states with a single value, not multiple booleans
When only one of several states can be active at a time (e.g. upvote/downvote/none), represent it as one tri-state value rather than independent booleans that can contradict.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetsx
| 1 | const [upvoted, setUpvoted] = useState(false); |
| 2 | const [downvoted, setDownvoted] = useState(false); |
| 3 | // nothing stops both being true at once |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | type Vote = true | false | null; // up | down | none |
| 2 | const [vote, setVote] = useState<Vote>(null); |
Explanation (EN)
Objašnjenje (HR)