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
stateloading-statenull-vs-emptyux
Use null for 'not yet loaded' and empty array for 'loaded but empty'
Reset collection state to null to mean not-yet-fetched and reserve [] for a fetched-but-empty result, so loading and empty UI states can be told apart.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetsx
| 1 | const resetPageState = () => { |
| 2 | setThreads([]); // can't tell loading from genuinely empty |
| 3 | }; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | const resetPageState = () => { |
| 2 | setThreads(null); // null = not fetched yet; [] = fetched, no results |
| 3 | }; |
Explanation (EN)
Objašnjenje (HR)