Skip to content

useQuery and useInfiniteQuery's return data gets mixed up #1255

Answered by TkDodo
ArnaudWeyts asked this question in Ideas
Discussion options

You must be logged in to vote

The return value of both queries should consistently be the data for useQuery or an array of data for useInfiniteQuery

My mental model of react-query is the following: the react query cache is just an object, and the serialized query key is the key of that object. When you fetch data from the backend, you put data into that cache and then just retrieve it via useQuery with a lookup. React-query will refetch and update that cache.

useQuery and useInfiniteQuery have different underlying data structures, so by using the same key, you are overriding the data. This is not a good idea - It’s like calling queryCache.setQueryData() and putting data of different structure into your cache.

My pro…

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ArnaudWeyts
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
5 participants
Converted from issue

This discussion was converted from issue #1255 on December 07, 2020 04:21.