Skip to content

Commit 475eb41

Browse files
authored
fix: rename asyncStoragePersistor to createAsyncStoragePersistor (TanStack#2421)
1 parent caf841a commit 475eb41

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

docs/src/pages/plugins/createAsyncStoragePersistor.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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'
2121
import { persistQueryClient } from 'react-query/persistQueryClient-experimental'
2222
import { 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
```

src/createAsyncStoragePersistor-experimental/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { PersistedClient, Persistor } from '../persistQueryClient-experimental'
2+
13
interface 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

79
interface 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
}

0 commit comments

Comments
 (0)