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 / React
readabilitydrycontrol-flowrefactor
Set shared variables in a switch, then call setters once afterward
When each switch branch repeats the same setState/setX calls, instead assign local variables in the branches and perform the setter calls once after the switch.
PR: hegnar-bellsheep-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codets
| 1 | switch (dir) { |
| 2 | case 'left': setSearchParams(a); setDate(a); break; |
| 3 | case 'right': setSearchParams(b); setDate(b); break; |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | let next; |
| 2 | switch (dir) { case 'left': next = a; break; case 'right': next = b; break; } |
| 3 | setSearchParams(next); setDate(next); |
Explanation (EN)
Objašnjenje (HR)