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
reacthooksuseeffectdependenciesperformance
Pass an empty dependency array for effects that should run once on mount
An effect meant to run only on mount (e.g. adding a one-time listener) must declare an empty deps array, otherwise it re-runs on every render.
PR: hegnar-zephr-components · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetsx
| 1 | useEffect(() => { |
| 2 | document.addEventListener('click', onOutside); |
| 3 | return () => document.removeEventListener('click', onOutside); |
| 4 | }); // runs every render |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | useEffect(() => { |
| 2 | document.addEventListener('click', onOutside); |
| 3 | return () => document.removeEventListener('click', onOutside); |
| 4 | }, []); |
Explanation (EN)
Objašnjenje (HR)