Query key conventions
I define query keys in one place so the whole app uses the same ones:
export const orderKeys = {
all: ["orders"] as const,
list: (f: { status: string; page: number }) => [...orderKeys.all, "list", f] as const,
detail: (id: string) => [...orderKeys.all, "detail", id] as const,
};
// After a mutation, invalidate every order list but keep unrelated caches warm
queryClient.invalidateQueries({ queryKey: orderKeys.all });
Optimistic updates for operations work
Dashboards for sellers and operators are used all day. For small, reversible actions (mark an order shipped, toggle a product’s visibility), an optimistic update makes the interface feel instant, with automatic rollback if the server rejects the change. For anything involving money, I wait for the server.
Where it sits in the architecture
TanStack Query lives in the container layer, as hooks such as useOrders() and useUpdateStock(). Presentational components receive plain props and never import the query client, which keeps them testable and reusable.