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
contextstate-managementfetchingarchitecture
Centralize fetch-and-reset logic in a context to avoid refetch-on-open
Move data fetching and state into a context so opening/closing UI reads existing state instead of refetching and resetting on every open.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetsx
| 1 | const handleOpen = () => { |
| 2 | setInstruments([]); // wipes state |
| 3 | fetchInstruments(); // refetch every open |
| 4 | setOpen(true); |
| 5 | }; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | // State lives in context and persists; opening only reads it. |
| 2 | const { instruments } = useWatchlistContext(); |
| 3 | const handleOpen = () => setOpen(true); |
Explanation (EN)
Objašnjenje (HR)