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 ruleP1stack specificStack: react
reactstate-managementderived-statesimplicity
Derive values during render instead of storing redundant state
If a value can be computed from existing state/props, compute it inline rather than holding it in its own useState and syncing it.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetsx
| 1 | const [itemCount, setItemCount] = useState(0); |
| 2 | const [isEmpty, setIsEmpty] = useState(true); |
| 3 | // ...later have to keep setIsEmpty in sync with itemCount everywhere |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | const [itemCount, setItemCount] = useState(0); |
| 2 | const isEmpty = itemCount === 0; // recomputed every render, no extra state |
Explanation (EN)
Objašnjenje (HR)