TanStackT
TanStack10mo ago
2 replies
ordinary-sapphire

Initial Data as Cache

I want to use react query as a offline backup cache. However I want to save a whole database table. Would it make sense to fetch all data like with pagination)

api/ratings

and then manually add all the routes like

api/ratings/1
api/ratings/2
api/ratings/3

So I always have all data in the cache just in case I loose connection.

Is this a valid way of doing it? Or is this something react query is not made to be.

https://tanstack.com/query/latest/docs/framework/react/guides/initial-query-data#initial-data-from-the-cache-with-initialdataupdatedat
There are many ways to supply initial data for a query to the cache before you need it: Declaratively: Provide initialData to a query to prepopulate its cache if empty Imperatively: Using initialData...
Initial Query Data | TanStack Query React Docs
Was this page helpful?