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
reactcompositioncomponentsreuse
Prefer composition over inheritance for UI components
When two components share some behavior but override others, compose them (children/props) instead of extending a base class.
PR: frontpage-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetsx
| 1 | class DayPickerHorizontal extends DayPickerList { |
| 2 | render() { /* redefines render, reuses some methods */ } |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | // Two sibling components sharing a stateless helper / child |
| 2 | const DayPickerButtons = ({ days }) => (...); |
| 3 | const DayPickerHorizontal = (p) => <DayPickerButtons {...p} />; |
| 4 | const DayPickerVertical = (p) => <DayPickerButtons {...p} />; |
Explanation (EN)
Objašnjenje (HR)