Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Avoid extra state writes that the render already guards
Don't add a class/flag in an effect when the JSX already conditionally applies it; the duplicate write causes extra renders.
Bad example
| 1 | useEffect(() => { |
| 2 | if (useColumnLayout) setUseColumnLayout(true); // already enforced in JSX |
| 3 | }, [useColumnLayout]); |
Explanation (EN)
A second representation of an already-derived flag introduces synchronization work and possible drift.
Objašnjenje (HR)
Good example
| 1 | // JSX already does: className={clsx(useColumnLayout && isBelowBreakpoint && 'column')} |
| 2 | // no extra effect needed |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Remove an effect or setter when the same flag is already fully determined by current props/state in rendering and it has no independent lifecycle purpose.
Exceptions / Tradeoffs (EN)
Keep synchronization with an external system or genuinely independent user state. Check every consumer before removing an imperative class update.