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
reacthooksuseeffectperformance
Do not reset state on mount when the keyed prop never changes
Avoid an effect that resets state on a prop that only sets once; it just causes an extra render on mount.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetsx
| 1 | useEffect(() => { |
| 2 | setData(initialFor(tickerName)); // tickerName never changes -> useless reset + extra render |
| 3 | }, [tickerName]); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | const [data, setData] = useState(() => initialFor(tickerName)); |
Explanation (EN)
Objašnjenje (HR)