I’m using React Query to manage my queries, and I have a scenario where I need to invalidate a query with specific parameters.
useQuery({
queryKey: ["users", { page: 2, pageSize: 20 }],
queryFn: () => fetchUsers(), // Function that fetches users
});
Currently, I’m on page 2 of the users list. After performing an edit operation successfully, I want to invalidate the query for page 1 (with the same pageSize parameter).
I tried this with queryClient.invalidateQueries, but it doesn't seem to work as expected.
queryClient.invalidateQueries({
queryKey: ["users", { page: 1, pageSize: 20 }], // Changing the params
});
How can I invalidate the query for page 1 after editing the data for page 2? Is there a way to invalidate the query with specific parameters like { page: 1, pageSize: 20 } without matching the exact reference?