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 ruleP2universalStack: javascript
timersreactcleanup
Choose setTimeout vs setInterval based on whether you need repetition
Use setInterval only when you genuinely need a recurring tick; converting a one-off setTimeout to setInterval (or vice versa) changes behavior, so make the choice deliberate and always clear the timer on unmount.
PR: frontpage-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codejavascript
| 1 | const interval = setInterval(() => { /* runs forever */ }, 1000); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | const timeout = setTimeout(() => { /* runs once */ }, 1000); |
| 2 | return () => clearTimeout(timeout); |
Explanation (EN)
Objašnjenje (HR)