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
dryhandlersstatereadability
Replace separate open/close handlers with a single toggle
When two handlers only set a boolean to true and false, collapse them into one toggle handler that negates the current value.
PR: frontpage-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codejavascript
| 1 | openCalendar = () => this.setState({ isExpanded: true }); |
| 2 | closeCalendar = () => this.setState({ isExpanded: false }); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | toggleCalendar = () => this.setState((s) => ({ isExpanded: !s.isExpanded })); |
Explanation (EN)
Objašnjenje (HR)