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
reactnull-safetyasyncstate
Guard derived calculations against undefined async state
When deriving values from state that starts null/undefined before an async fetch resolves, guard against the nullish case instead of computing directly on possibly-undefined fields.
PR: vinify-frontend · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetsx
| 1 | const [info, setInfo] = useState(null); |
| 2 | const { ratedCount, tastedCount } = info || {}; |
| 3 | const total = ratedCount + tastedCount; // NaN before fetch resolves |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | const [info, setInfo] = useState(null); |
| 2 | if (!info) return <Skeleton />; |
| 3 | const total = info.ratedCount + info.tastedCount; |
Explanation (EN)
Objašnjenje (HR)