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
hookscontextapi-design
Expose a purpose-named hook instead of a generic nullable context accessor
When a context is read for exactly one thing, export a hook named for that thing (`useAdFree()` returning a boolean) rather than a generic `useXOrNull()` that every caller has to unwrap.
PR: hegnar-web#4698 FCK-3550 Drive ad suppression from the article flagCreated: Sep 7, 2026
Bad example
Old codets
| 1 | export function useRequestResponseOrNull() { return use(Ctx); } |
| 2 | // callers: useRequestResponseOrNull()?.res.locals.adFree |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | export function useAdFree() { return use(Ctx)?.res.locals.adFree ?? false; } |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
The narrow hook centralises the fallback and gives the value a name at every call site.