InvalidateQueries of multiple keys
If I have a query such as this:
const todoListQuery = useQuery({
queryKey: ['todosFull', 'todoSpecific'],
queryFn: fetchTodoList,
})
and then I invalidate the query with queryClient.invalidateQueries({ queryKey: ['todoSpecific'] })
Should that work? or do I need to do queryClient.invalidateQueries({ queryKey: ['todosFull', 'todoSpecific'] }) for it
4 Replies
environmental-rose•3y ago
Yes that works
Except if you pass the
exact flagexotic-emerald•3y ago
no, it wouldn't work. arrays have an order. The key
['todosFull', 'todoSpecific'] would be targeted by:
or, of course:
I have a blogpost on this: https://tkdodo.eu/blog/effective-react-query-keysEffective React Query Keys
Learn how to structure React Query Keys effectively as your App grows
environmental-rose•3y ago
Oops, did not read it right 🙃
extended-salmonOP•3y ago
Always ends up with the solution in your blogposts, should be advertised more! Thanks again