about summary refs log tree commit diff
path: root/src/lib/react-query.ts
diff options
context:
space:
mode:
authorMinseo Lee <itoupluk427@gmail.com>2024-03-19 10:52:29 +0900
committerMinseo Lee <itoupluk427@gmail.com>2024-03-19 10:52:29 +0900
commitad43d594c9f63fc85e6927d23cd3f3f21406b002 (patch)
tree8a20f9f9051ff066bd54c5bc126ccc548e2cb16c /src/lib/react-query.ts
parent73dae9f7b5c169aa303e9ef9487040e850998edf (diff)
parent3abf302b0b189c50acf11489bf60bdaeb187b722 (diff)
downloadvoidsky-ad43d594c9f63fc85e6927d23cd3f3f21406b002.tar.zst
Merge remote-tracking branch 'upstream/main' into patch-3
Diffstat (limited to 'src/lib/react-query.ts')
-rw-r--r--src/lib/react-query.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lib/react-query.ts b/src/lib/react-query.ts
index 7fe3fe7a4..d6cd3c54b 100644
--- a/src/lib/react-query.ts
+++ b/src/lib/react-query.ts
@@ -1,7 +1,14 @@
 import {AppState, AppStateStatus} from 'react-native'
 import {QueryClient, focusManager} from '@tanstack/react-query'
+import {createAsyncStoragePersister} from '@tanstack/query-async-storage-persister'
+import AsyncStorage from '@react-native-async-storage/async-storage'
+import {PersistQueryClientProviderProps} from '@tanstack/react-query-persist-client'
+
 import {isNative} from '#/platform/detection'
 
+// any query keys in this array will be persisted to AsyncStorage
+const STORED_CACHE_QUERY_KEYS = ['labelers-detailed-info']
+
 focusManager.setEventListener(onFocus => {
   if (isNative) {
     const subscription = AppState.addEventListener(
@@ -48,3 +55,16 @@ export const queryClient = new QueryClient({
     },
   },
 })
+
+export const asyncStoragePersister = createAsyncStoragePersister({
+  storage: AsyncStorage,
+  key: 'queryCache',
+})
+
+export const dehydrateOptions: PersistQueryClientProviderProps['persistOptions']['dehydrateOptions'] =
+  {
+    shouldDehydrateMutation: (_: any) => false,
+    shouldDehydrateQuery: query => {
+      return STORED_CACHE_QUERY_KEYS.includes(String(query.queryKey[0]))
+    },
+  }