Skip to content

keepPreviousData deprecated - what now? #6460

Answered by TkDodo
ffxsam asked this question in Q&A
Discussion options

You must be logged in to vote

and when I navigate through our app, I always see the previously cached data shown.

That's the default behaviour, yes, but it has nothing to do with placeholderData. When you navigate through your app, you likely change components, and those have different useQuery calls, observering different parts of the cache. When cached data is available, you'll always get it plus potentially a background refetch (stale-while-revalidate).

What keepPreviousData (and the placholderData function replacement in v5) does is give you data from the previous query when you change from one query to the next in the same observer (component). That usually happens when the queryKey changes. It's meant to give …

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
3 replies
@ffxsam
Comment options

@TkDodo
Comment options

Answer selected by ffxsam
@ffxsam
Comment options

Comment options

You must be logged in to vote
2 replies
@LeulAria
Comment options

@hnrchrdl
Comment options

# for free to join this conversation on GitHub. Already have an account? # to comment
Category
Q&A
Labels
None yet
5 participants