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
reactstatesimplicityderived-state
Consolidate tightly-coupled state into a single variable
When two state values always change together (e.g. snackbar message and open flag), model them as one piece of state derived appropriately.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetsx
| 1 | const [message, setMessage] = useState(''); |
| 2 | const [open, setOpen] = useState(false); // open is just message !== '' |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | const [message, setMessage] = useState(''); |
| 2 | const open = message !== ''; |
Explanation (EN)
Objašnjenje (HR)