T
TanStackโ€ข3y ago
genetic-orange

How to use PersistQueryClientProvider to persist to IndexedDb

What needs to be changed in this code snippet, to work with IndexedDB? const persister = createSyncStoragePersister({ storage: window.localStorage, }) Code snippet from the documentation: https://tanstack.com/query/latest/docs/react/plugins/persistQueryClient I created an indexeddb persister according to the documentation, but I get errors when I call it. TypeError: storage.getItem is not a function
persistQueryClient | TanStack Query Docs
This is set of utilities for interacting with "persisters" which save your queryClient for later use. Different persisters can be used to store your client and cache to many different storage layers. Build Persisters
2 Replies
rare-sapphire
rare-sapphireโ€ข3y ago
Hi ๐Ÿ‘‹ Please see https://github.com/TanStack/query/discussions/3198#discussioncomment-2174399 to do exactly this ๐Ÿ™‚
GitHub
IndexedDb Persister ยท TanStack query ยท Discussion #3198
Now that we have better persister in react-query v4 alpha ๐Ÿš€, I was also going to see about sharing my IndexedDb persister. It's super easy: import { get, set, del } from "idb-keyva...
genetic-orange
genetic-orangeOPโ€ข3y ago
I tried with this code const persister = createAsyncStoragePersister({ storage: createIDBPersister(), }); But it's only saving the word "REACT_QUERY_OFFLINE_CACHE" to indexeddb, and I'm getting an error in the console SyntaxError: Unexpected token 'R', "REACT_QUER"... is not valid JSON Thanks

Did you find this page helpful?