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: React
reacthookstimingclean-code
Avoid setTimeout in effects unless genuinely required
Don't wrap effect logic in setTimeout(0) by default; only use it when a real timing/focus issue requires deferring to the next tick, and document why.
PR: hegnar-components · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetsx
| 1 | useEffect(() => { |
| 2 | setTimeout(() => inputRef.current?.focus(), 0); // why? |
| 3 | }, []); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | useEffect(() => { |
| 2 | inputRef.current?.focus(); |
| 3 | }, []); |
| 4 | // keep setTimeout only if focus/select genuinely won't work synchronously, and add a comment |
Explanation (EN)
Objašnjenje (HR)