diff options
author | Samuel Newman <mozzius@protonmail.com> | 2024-03-19 15:18:29 +0000 |
---|---|---|
committer | Samuel Newman <mozzius@protonmail.com> | 2024-03-19 15:18:29 +0000 |
commit | f491bd89cc28cba46a92b443e1f07ff73e8f7128 (patch) | |
tree | 8f7c34372afe1f600a5626ef72dd9c8b28b930a6 /src/lib/react-query.ts | |
parent | d2a11f3344149a299372f0a7dcd01de9f58ef9a1 (diff) | |
parent | 9c49b209ca9eda8e6fab0942f7046d335c955c1a (diff) | |
download | voidsky-f491bd89cc28cba46a92b443e1f07ff73e8f7128.tar.zst |
Merge remote-tracking branch 'origin/main' into samuel/alf-login
Diffstat (limited to 'src/lib/react-query.ts')
-rw-r--r-- | src/lib/react-query.ts | 20 |
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])) + }, + } |