Using previous stale data while refetching
How do you deal with data while fetching, it seems that while the refetch is happening, the data is undefined, unless you use placeholderData/initialData.
Is it possible to return placeholderData during the first fetch only, and the previous stale data after that while refetching? Currently the placeholderData is shown during every refetch which messes with animated transitions between the data values.
3 Replies
multiple-amethyst•3y ago
Have a look at the
keepPreviousData option of useQuery: https://tanstack.com/query/v4/docs/react/reference/useQuery.
I actually tweeted about this recently: https://twitter.com/Julien_Delort/status/1615358389311135751stormy-goldOP•3y ago
Great! That's just what I needed, hadn't noticed that... thanks!
multiple-amethyst•3y ago
no problem!!