Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Set related state in one call to avoid double renders
Group related state transitions for clarity; verify actual React batching before claiming fewer renders.
Bad example
| 1 | this.setState({ selectedIndex: i }); |
| 2 | this.setState({ inputText: '' }); |
Explanation (EN)
Splitting one logical class-state transition across calls can obscure which fields must change together.
Objašnjenje (HR)
Good example
| 1 | this.setState({ selectedIndex: i, inputText: '' }); |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Group fields that represent one state transition when doing so clarifies their invariant and preserves update ordering.
Exceptions / Tradeoffs (EN)
Modern React already batches many updates; two setter calls do not necessarily mean two renders. Distinct state owners can remain separate, and updates based on prior state need functional setters.