File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed
src/createAsyncStoragePersisor-experimental Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change 11import AsyncStorage from '@react-native-community/async-storage'
22
3- export const asyncStoragePersistor = ( { asyncStorageKey, throttleTime } ) => {
3+ interface CreateAsyncStoragePersistorOptions {
4+ /** The key to use when storing the cache */
5+ key ?: string
6+ /** To avoid spamming,
7+ * pass a time in ms to throttle saving the cache to disk */
8+ throttleTime ?: number
9+ }
10+
11+ export const asyncStoragePersistor = ( {
12+ key,
13+ throttleTime,
14+ } : CreateAsyncStoragePersistorOptions ) => {
415 return {
516 persistClient : throttle ( function ( persistedClient ) {
6- AsyncStorage . setItem ( asyncStorageKey , JSON . stringify ( persistedClient ) )
17+ AsyncStorage . setItem ( key , JSON . stringify ( persistedClient ) )
718 } , throttleTime ) ,
819 restoreClient : async function restoreClient ( ) {
9- const cacheString = await AsyncStorage . getItem ( asyncStorageKey )
20+ const cacheString = await AsyncStorage . getItem ( key )
1021
1122 if ( ! cacheString ) {
1223 return
@@ -15,7 +26,7 @@ export const asyncStoragePersistor = ({ asyncStorageKey, throttleTime }) => {
1526 return JSON . parse ( cacheString )
1627 } ,
1728 removeClient : function removeClient ( ) {
18- AsyncStorage . removeItem ( asyncStorageKey )
29+ AsyncStorage . removeItem ( key )
1930 } ,
2031 }
2132}
You can’t perform that action at this time.
0 commit comments