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
reactlifecycleseparation-of-concerns
Keep prop-change lifecycle hooks limited to reacting to prop changes
In componentWillReceiveProps (or equivalent), compare props and trigger updates; keep component logic out and share repeated checks in the called method.
PR: frontpage-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codejavascript
| 1 | componentWillReceiveProps(next) { |
| 2 | if (next.shouldRefresh && this.slot && this.slot.isLoaded) { |
| 3 | this.observe(); |
| 4 | } |
| 5 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | componentWillReceiveProps(next) { |
| 2 | if (next.shouldRefresh) this.observe(); |
| 3 | } |
| 4 | observe() { |
| 5 | if (!this.slot || !this.slot.isLoaded) return; |
| 6 | // ...observe logic centralized here |
| 7 | } |
Explanation (EN)
Objašnjenje (HR)