TanStackT
TanStack2y ago
12 replies
homeless-violet

queryClient.fetchQuery persister

Hey guys,

I have setup a mobile app using Capacitor and Ionic, and I'm using react-query to manage my API calls. I created an asyncStoragePersister using a cordova sqlite plugin to store the cache on the mobile phone and allow offline usage of the app without having to persist data myself. It seems to work pretty well.
The problem is, my app is protected by an auth, and I have to add my user profile fetch in this auth setup, which is outside React (not a component).

After some look, I find that I can use react-query outside of a component using my queryClient which I export, with a fetchQuery. I managed to make it work, but it doesn't use the persister since it is not declared inside the queryClient itself but in the react-query context.

Is there any way to also stick my persister to the queryClient when used outside of react ?

Thanks.
Was this page helpful?