Skip to content

Does invalidateQueries accept a list of query keys? #10612

Closed

Description

@dev-mashael-otb

Describe the bug

Hi ,

when I tried to invalidate multiple queries like this:

queryClient.invalidateQueries({ queryKey: ['queryKeyOne', 'queryKeyTwo'] });

it’s not working ... it does not invalidate both queries

so is there any solution to invalidate multiple query keys?

Your minimal, reproducible example

import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';

function Example() {
const queryClient = useQueryClient();

useQuery({ queryKey: ['queryKeyOne'],
queryFn: () => Promise.resolve('data1'), });

useQuery({ queryKey: ['queryKeyTwo'],
queryFn: () => Promise.resolve('data2'), });

const mutation = useMutation({
mutationFn: () => Promise.resolve(true),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['queryKeyOne', 'queryKeyTwo'] });
}, });

return (
<button onClick={() => mutation.mutate()}> invalidateQueries
); }

Steps to reproduce

  1. Create two queries with different keys:

    • ['queryKeyOne']
    • ['queryKeyTwo']
  2. Call:
    queryClient.invalidateQueries({ queryKey: ['queryKeyOne', 'queryKeyTwo'] });

  3. Check the network or React Query Devtools

  4. Notice that neither query is invalidated

Expected behavior

Both queries ['queryKeyOne'] and ['queryKeyTwo'] should be invalidated when calling

queryClient.invalidateQueries({ queryKey: ['queryKeyOne', 'queryKeyTwo'] });

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

macOS

Tanstack Query adapter

@tanstack/react-query

TanStack Query version

"@tanstack/react-query": "^5.17.9"

TypeScript version

"typescript": "^5"

Additional context

No response

Activity

  1. sccolbert commented on Apr 29, 2026

    @sccolbert

    I don't believe it does. But it does do prefix matching. So let's say you have two query keys:

    key1 = ['pages', 'foo']
    key2 = ['pages', 'bar']

    Then you can invalidate all pages with:

    client.invalidateQueries({ queryKey: ['pages'] });
  2. locked and limited conversation to collaborators on Apr 30, 2026
  3. converted this issue into a discussion #10613 on Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions