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 ruleP1universalStack: React
reactcontextdryreusestate-management
Extract repeated cross-component logic into context and helper functions
When the same stateful logic appears in multiple components, lift it into a shared context plus a wrapper helper instead of re-implementing it each place.
PR: abcn-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetsx
| 1 | // each component re-derives login state from cookies |
| 2 | useEffect(() => { |
| 3 | setIsLoggedUser(document.cookie.includes('__utp')); |
| 4 | }, []); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | // shared context + helper, consumed everywhere |
| 2 | const { isLoggedUser } = useAuthContext(); |
Explanation (EN)
Objašnjenje (HR)