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
reactstatenull-safetytypes
Initialize array-typed state with an empty array, not undefined
When a state value is typed as an array, initialize it with [] rather than undefined so consumers can iterate safely and the value matches its declared type.
PR: vinify-frontend · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codets
| 1 | const [items, setItems] = useState<Item[]>(); // value is undefined initially |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | const [items, setItems] = useState<Item[]>([]); |
Explanation (EN)
Objašnjenje (HR)