T
TanStack3y ago
criminal-purple

InvalidateQueries not refetching with dynamic key

I'm trying abstract away some boilerplate in our application. So, the queryKey is assigned by a prop in our case. The list view works great, and the delete action also. But when I want to refresh the list (after deleting), nothing happens. Query looks like:
const { isLoading, data, isError, error } = useQuery({
queryKey: [entityKey, "list", pagination],
queryFn: () => operations.list(),
retry: false,
refetchOnWindowFocus: false,
refetchOnMount: false,
refetchOnReconnect: false,
},
});
const { isLoading, data, isError, error } = useQuery({
queryKey: [entityKey, "list", pagination],
queryFn: () => operations.list(),
retry: false,
refetchOnWindowFocus: false,
refetchOnMount: false,
refetchOnReconnect: false,
},
});
- queryClient.invalidateQueries([entityKey]); does nothing - queryclient.invalidateQueries() also, does not refresh According to the docs, just calling it with [entityKey] should expire all of the entity data, like list with pagination. The delete API call is being executed directly (without mutation), is that necessary so that I can call invalidateQueries correctly?
1 Reply
criminal-purple
criminal-purpleOP3y ago
OK, figured it out and hope if someone else does something similarly stupid - it will save them some time. I was calling my "refresh" callback before actually mutating anything insert facepalm. So absolutely nothing wrong with React Query 👍

Did you find this page helpful?