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 ruleP1stack specificStack: React
reactside-effectssetStatepurity
Don't run side effects inside a setState updater
State updater callbacks should be pure; perform async/side-effect work (fetches, debounced syncs) in an effect or event handler, not inside setState.
PR: hegnar-forum-web · org-mining-3rd-2026-06Created: Jun 18, 2026
Bad example
Old codetsx
| 1 | setVote(prev => { |
| 2 | const next = prev === desired ? null : desired; |
| 3 | debouncedSync(direction, next); // side effect inside updater |
| 4 | return next; |
| 5 | }); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | const next = vote === desired ? null : desired; |
| 2 | setVote(next); |
| 3 | useEffect(() => { debouncedSync(direction, next); }, [next]); |
Explanation (EN)
Objašnjenje (HR)