add a more specific queryKey pattern (#45459)

Action item for Frontend Team Sync Agenda.
I decided to duplicate the pattern/rule in both files until we
eventually unify them.
This commit is contained in:
Nico
2026-05-21 13:26:20 -03:00
committed by GitHub
parent 874311f38a
commit 6b0551e922
2 changed files with 36 additions and 3 deletions
+17
View File
@@ -397,6 +397,23 @@ const PageOrComponent = (props) => {
};
```
##### Query keys
The `queryKey` must list every parameter that the `queryFn` passes to the API. The `QueryClient` is a singleton shared across the app, so any parameter missing from the key causes cross-entity cache bleed (for example, data fetched for team A being served to team B).
Rules:
- Always use an array, even when there are no parameters — `useQuery(["me"], ...)`, not `useQuery("me", ...)`.
- Every argument the `queryFn` forwards to the API must also appear in the key.
Example:
```ts
useQuery(
["aggregateProfileStatuses", teamId], // teamId is in the key...
() => mdmAPI.getProfilesStatusSummary(teamId) // ...because the API call receives it
);
```
### Handling API errors
We pull the logic for handling error message into a `getErrorMessage` handler that lives in a sibling