Guest User

queryClient.ts

a guest
Oct 13th, 2023
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister'
  2. import AsyncStorage from '@react-native-async-storage/async-storage';
  3. import { MutationCache, QueryClient } from '@tanstack/react-query'
  4. import { CrashReporting } from 'instabug-reactnative';
  5.  
  6. export const persister = createAsyncStoragePersister({
  7.   storage: AsyncStorage,
  8.   throttleTime: 500,
  9.   key: "REACT_QUERY_OFFLINE_CACHE",
  10. });
  11.  
  12. export const queryClient = new QueryClient({
  13.   defaultOptions: {
  14.     queries: {
  15.       networkMode: 'online',
  16.       staleTime: Infinity,
  17.       cacheTime: Infinity, // 24 hours
  18.       // staleTime: Infinity, // longer staleTimes result in queries not being re-fetched as often
  19.       refetchOnReconnect: 'always',
  20.       retry: 3,
  21.       retryDelay: 3000,
  22.       refetchOnWindowFocus: true,
  23.       refetchOnMount: true
  24.     },
  25.     mutations: {
  26.       cacheTime: Infinity,
  27.     }
  28.   },
  29.   mutationCache: new MutationCache({
  30.     onSuccess: (data) => {
  31.       console.log('[ Mutation Cache Processed ]:', data)
  32.     },
  33.     onError: (error) => {
  34.       console.log('[ Mutation Cache Error ]:', error)
  35.       CrashReporting.reportError(error);
  36.       throw error
  37.     }
  38.   })
  39. });
Add Comment
Please, Sign In to add comment