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
reactcontextcomponent-designcoupling
Make a component's context dependency obvious to consumers
A reusable component that consumes a context should either take the data via props or wrap itself with the required provider, so callers aren't surprised by a hidden dependency.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetsx
| 1 | // components/Filters.tsx — silently requires FrontpageContextProvider |
| 2 | const Filters = () => { |
| 3 | const { data } = useFrontpageCtx(); |
| 4 | return <div>{data}</div>; |
| 5 | }; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | // take data via props so the dependency is explicit |
| 2 | const Filters = ({ data }: { data: FilterData }) => <div>{data}</div>; |
| 3 | // or render the provider at this component's level |
Explanation (EN)
Objašnjenje (HR)