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
reacthooksmemoizationreferential-equality
Avoid a fresh default array/object in a hook dependency
Defaulting to [] or {} inside render creates a new reference each render, defeating memoization. Use optional chaining with ?? in the body instead.
PR: hegnar-bellsheep-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codets
| 1 | const list = data[key] || []; |
| 2 | const years = useMemo(() => list.map(i => i.year), [list]); // list is new every render |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | const years = useMemo(() => data[key]?.map(i => i.year).sort() ?? [], [data, key]); |
Explanation (EN)
Objašnjenje (HR)