File tree Expand file tree Collapse file tree 2 files changed +11
-9
lines changed
src/createAsyncStoragePersistor-experimental Expand file tree Collapse file tree 2 files changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ This utility comes packaged with `react-query` and is available under the `react
1717- Pass it to the [ ` persistQueryClient ` ] ( ../persistQueryClient ) function
1818
1919``` ts
20- import AsyncStorage from ' @react-native-community /async-storage'
20+ import AsyncStorage from ' @react-native-async-storage /async-storage'
2121import { persistQueryClient } from ' react-query/persistQueryClient-experimental'
2222import { createAsyncStoragePersistor } from ' react-query/createAsyncStoragePersistor-experimental'
2323
@@ -56,7 +56,7 @@ interface CreateAsyncStoragePersistorOptions {
5656 /** The storage client used for setting an retrieving items from cache */
5757 storage: AsyncStorage
5858 /** The key to use when storing the cache to localstorage */
59- asyncStorageKey ? : string
59+ key ? : string
6060 /** To avoid localstorage spamming,
6161 * pass a time in ms to throttle saving the cache to disk */
6262 throttleTime? : number
@@ -73,7 +73,7 @@ The default options are:
7373
7474``` js
7575{
76- asyncStorageKey = ` REACT_QUERY_OFFLINE_CACHE` ,
76+ key = ` REACT_QUERY_OFFLINE_CACHE` ,
7777 throttleTime = 1000 ,
7878}
7979```
Original file line number Diff line number Diff line change 1+ import { PersistedClient , Persistor } from '../persistQueryClient-experimental'
2+
13interface AsyncStorage {
2- getItem : ( key : string ) => Promise < string >
3- setItem : ( key : string , value : string ) => Promise < unknown >
4- removeItem : ( key : string ) => Promise < unknown >
4+ getItem : ( key : string ) => Promise < string | null >
5+ setItem : ( key : string , value : string ) => Promise < void >
6+ removeItem : ( key : string ) => Promise < void >
57}
68
79interface CreateAsyncStoragePersistorOptions {
@@ -14,11 +16,11 @@ interface CreateAsyncStoragePersistorOptions {
1416 throttleTime ?: number
1517}
1618
17- export const asyncStoragePersistor = ( {
19+ export const createAsyncStoragePersistor = ( {
1820 storage,
1921 key = `REACT_QUERY_OFFLINE_CACHE` ,
2022 throttleTime = 1000 ,
21- } : CreateAsyncStoragePersistorOptions ) => {
23+ } : CreateAsyncStoragePersistorOptions ) : Persistor => {
2224 return {
2325 persistClient : asyncThrottle (
2426 persistedClient => storage . setItem ( key , JSON . stringify ( persistedClient ) ) ,
@@ -31,7 +33,7 @@ export const asyncStoragePersistor = ({
3133 return
3234 }
3335
34- return JSON . parse ( cacheString )
36+ return JSON . parse ( cacheString ) as PersistedClient
3537 } ,
3638 removeClient : ( ) => storage . removeItem ( key ) ,
3739 }
You can’t perform that action at this time.
0 commit comments