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
componentscompositionduplicationguards
Encapsulate a repeated conditional-render guard in a wrapper component
When the same `if (flag) return null` guard is copied into several components, express it once as a wrapper (`<AdSurface>{children}</AdSurface>`) so the guard is declarative and a missing one is visible in review.
PR: hegnar-web#4698 FCK-3550 Drive ad suppression from the article flagCreated: Sep 7, 2026
Bad example
Old codets
| 1 | // in 5 components |
| 2 | if (useAdFree()) return null; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | export function AdSurface({ children }) { |
| 2 | return useAdFree() ? null : <>{children}</>; |
| 3 | } |
| 4 | // <AdSurface>...</AdSurface> around every ad surface |
Explanation (EN)
Objašnjenje (HR)