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 ruleP2universalStack: react
reactmodalsdata-fetchingcolocation
Fetch modal data on the modal's mount, not on the button that opens it
Move data fetching into the modal so it loads when the modal mounts, instead of triggering the fetch from the opening button in the parent.
PR: hegnar-journalist-boost · org-mining-deep-2026-06Created: Jun 17, 2026
Bad example
Old codetsx
| 1 | <button onClick={() => { fetchUsers(); setOpen(true); }}>Share</button> |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | function ShareModal() { |
| 2 | const { data: users } = useQuery({ queryKey: ['users'], queryFn: fetchUsers }); |
| 3 | // fetches when the modal mounts |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)