Skip to content

useQueries doesn't work with 'keepPreviousData' properly #2181

@TIS-OMiddle

Description

@TIS-OMiddle

Describe the bug

  const [count, setCount] = useState(0);
  const result = useQueries(
    [1, 2].map((item) => {
      return {
        queryKey: [item, count],
        queryFn: queryFn,
        keepPreviousData: true
      };
    })
  );

The result[x].data should be "previousData" when queryKey change, but it is undefined.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/usequeries-with-keeppreviousdata-c9cim?file=/src/index.js:559-781
  2. Click '++count'
  3. See result[x].data

Expected behavior
result[x].data should always be {} when query key changed

Screenshots
image

Desktop (please complete the following information):

  • OS: Mac
  • Browser: chrome
  • Version: v90

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