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
reacthooksuseCallbackuseEffectsimplicity
Define effect-only helpers inside the effect to avoid useCallback
If a function is only used inside one effect, declare it inside that effect instead of wrapping it in useCallback and listing it as a dependency.
PR: hegnar-bellsheep-web · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codetsx
| 1 | const handler = useCallback(() => doWork(), []); |
| 2 |
|
| 3 | useEffect(() => { |
| 4 | window.addEventListener('resize', handler); |
| 5 | return () => window.removeEventListener('resize', handler); |
| 6 | }, [handler]); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | useEffect(() => { |
| 2 | const handler = () => doWork(); |
| 3 | window.addEventListener('resize', handler); |
| 4 | return () => window.removeEventListener('resize', handler); |
| 5 | }, []); |
Explanation (EN)
Objašnjenje (HR)