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 ruleP2stack specificStack: react
state-managementcontextprop-drillingreact
Don't reach for context when state is only passed a couple levels down
Use React context only when state must travel three or more levels or to many consumers; for shallow passing keep it as local state and props.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetsx
| 1 | // Placed in context, but the setter is called in one component |
| 2 | // and the value is read just 2 levels down |
| 3 | const { sortDirection, setSortDirection } = useThreadCtx(); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | // Local state passed down 2 levels via props is simpler than context |
| 2 | const [sortDirection, setSortDirection] = useState(SortOrder.DESC); |
| 3 | <RepliesHeader sortDirection={sortDirection} onSortChange={setSortDirection} /> |
Explanation (EN)
Objašnjenje (HR)