Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
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.
Bad example
| 1 | const resetPageState = () => { |
| 2 | setThreads([]); // can't tell loading from genuinely empty |
| 3 | }; |
Explanation (EN)
One empty array used for both reset/loading and successful emptiness loses state meaning.
Objašnjenje (HR)
Good example
| 1 | const resetPageState = () => { |
| 2 | setThreads(null); // null = not fetched yet; [] = fetched, no results |
| 3 | }; |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Represent loading, success-empty and failure separately when the UI needs to distinguish them, using the established state model.
Exceptions / Tradeoffs (EN)
null is only one option; a discriminated status or query library already models this. Do not add redundant null state when loading/error are represented elsewhere.