Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister'
- import AsyncStorage from '@react-native-async-storage/async-storage';
- import { MutationCache, QueryClient } from '@tanstack/react-query'
- import { CrashReporting } from 'instabug-reactnative';
- export const persister = createAsyncStoragePersister({
- storage: AsyncStorage,
- throttleTime: 500,
- key: "REACT_QUERY_OFFLINE_CACHE",
- });
- export const queryClient = new QueryClient({
- defaultOptions: {
- queries: {
- networkMode: 'online',
- staleTime: Infinity,
- cacheTime: Infinity, // 24 hours
- // staleTime: Infinity, // longer staleTimes result in queries not being re-fetched as often
- refetchOnReconnect: 'always',
- retry: 3,
- retryDelay: 3000,
- refetchOnWindowFocus: true,
- refetchOnMount: true
- },
- mutations: {
- cacheTime: Infinity,
- }
- },
- mutationCache: new MutationCache({
- onSuccess: (data) => {
- console.log('[ Mutation Cache Processed ]:', data)
- },
- onError: (error) => {
- console.log('[ Mutation Cache Error ]:', error)
- CrashReporting.reportError(error);
- throw error
- }
- })
- });
Add Comment
Please, Sign In to add comment