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
hookscontextindirectionyagni
Don't wrap a context read in a hook that has exactly one consumer
A hook earns its existence through reuse; when only one component reads a value off a context, call `use(Context)` in that component and keep the explanatory comment there, instead of exporting a single-use hook from the context module.
PR: hegnar-web#4698 FCK-3550 review round 2Created: Sep 8, 2026
Bad example
Old codets
| 1 | // RequestResponse.ts |
| 2 | export function useAdFree() { return use(Ctx)?.res.locals.adFree ?? false; } |
| 3 | // AdSurface.tsx (the only caller) |
| 4 | return useAdFree() ? null : children; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | // AdSurface.tsx |
| 2 | return use(RequestResponseContext)?.res.locals.adFree ? null : <>{children}</>; |
Explanation (EN)
Objašnjenje (HR)