Zen
Zen13mo ago

Caching(?) previous data until query returns new data

when I update my useQuery inputs with new filters it instantly sets the data to undefined while the query isLoading. Is there a way to keep the previous data there until the new data returns from the server? Currently there's big flashes in the UI between applications of the filters, as my data length drops to effectively zero then bounced back up again when the new data loads
1 Reply
Zen
Zen13mo ago
nevermind, found it. There's a flag you can put on the query keepPreviousData:true - https://tanstack.com/query/v4/docs/react/guides/paginated-queries#better-paginated-queries-with-keeppreviousdata
Paginated / Lagged Queries | TanStack Query Docs
Rendering paginated data is a very common UI pattern and in TanStack Query, it "just works" by including the page information in the query key: