Skip to content

use setQueriesData with InfiniteQueries #9183

Closed as not planned
Closed as not planned
@chris-acuvity

Description

@chris-acuvity

Describe the bug

Hi there,

I have been looking at the documentation and experimenting with setQueriesData using the latest version of React Query.

For some reason, the oldData is always undefined

Your minimal, reproducible example

See code below

Steps to reproduce

Here is an example of code:

queryClient.setQueriesData(
        {
          queryKey, // The query key correctly filters my queries
        },
        (oldData) => {
          // oldData is retrieve when the query has been made with useQuery but not useInfiniteQuery
          console.log(">>", queryKey, oldData); 

          // Do any immutable change here if needed
          return oldData
        }
      );

Expected behavior

I was expecting to get the data and be able to modify an object if the identifier matches

I am wondering if it's a known expectation as useInfiniteQuery returns an object containing the pages and the pageParams.

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

Chrome on macOS

Tanstack Query adapter

None

TanStack Query version

5.76.2

TypeScript version

6.15.0

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions