Skip to content

Commit cf09241

Browse files
authored
docs: update asyncStoragePersistor docs to match the current api (TanStack#2411)
1 parent 7a628d6 commit cf09241

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

docs/src/pages/plugins/createAsyncStoragePersistor.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
id: createAsyncStoragePersistor
3-
title: createAsyncStoragePersistor for React Native (Experimental)
3+
title: createAsyncStoragePersistor (Experimental)
44
---
55

66
> VERY IMPORTANT: This utility is currently in an experimental stage. This means that breaking changes will happen in minor AND patch releases. Use at your own risk. If you choose to rely on this in production in an experimental stage, please lock your version to a patch-level version to avoid unexpected breakages.
@@ -13,9 +13,11 @@ This utility comes packaged with `react-query` and is available under the `react
1313

1414
- Import the `createAsyncStoragePersistor` function
1515
- Create a new asyncStoragePersistor
16+
- you can pass any `storage` to it that adheres to the `AsyncStorage` interface - the example below uses the async-storage from React Native
1617
- Pass it to the [`persistQueryClient`](../persistQueryClient) function
1718

1819
```ts
20+
import AsyncStorage from '@react-native-community/async-storage'
1921
import { persistQueryClient } from 'react-query/persistQueryClient-experimental'
2022
import { createAsyncStoragePersistor } from 'react-query/createAsyncStoragePersistor-experimental'
2123

@@ -27,7 +29,9 @@ const queryClient = new QueryClient({
2729
},
2830
})
2931

30-
const asyncStoragePersistor = createAsyncStoragePersistor()
32+
const asyncStoragePersistor = createAsyncStoragePersistor({
33+
storage: AsyncStorage
34+
})
3135

3236
persistQueryClient({
3337
queryClient,
@@ -39,24 +43,30 @@ persistQueryClient({
3943

4044
### `createAsyncStoragePersistor`
4145

42-
Call this function (with an optional options object) to create a asyncStoragePersistor that you can use later with `persisteQueryClient`.
46+
Call this function to create an asyncStoragePersistor that you can use later with `persisteQueryClient`.
4347

4448
```js
45-
createAsyncStoragePersistor(options?: CreateAsyncStoragePersistorOptions)
49+
createAsyncStoragePersistor(options: CreateAsyncStoragePersistorOptions)
4650
```
4751

4852
### `Options`
4953

50-
An optional object of options:
51-
52-
```js
54+
```ts
5355
interface CreateAsyncStoragePersistorOptions {
56+
/** The storage client used for setting an retrieving items from cache */
57+
storage: AsyncStorage
5458
/** The key to use when storing the cache to localstorage */
5559
asyncStorageKey?: string
5660
/** To avoid localstorage spamming,
5761
* pass a time in ms to throttle saving the cache to disk */
5862
throttleTime?: number
5963
}
64+
65+
interface AsyncStorage {
66+
getItem: (key: string) => Promise<string>
67+
setItem: (key: string, value: string) => Promise<unknown>
68+
removeItem: (key: string) => Promise<unknown>
69+
}
6070
```
6171

6272
The default options are:

docs/src/pages/plugins/createWebStoragePersistor.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ const queryClient = new QueryClient({
2727
},
2828
})
2929

30-
const localStoragePersistor = createWebStoragePersistor({storage: window.localStorage})
31-
// const sessionStoragePersistor = createWebStoragePersistor({storage: window.sessionStorage})
30+
const localStoragePersistor = createWebStoragePersistor({ storage: window.localStorage })
31+
// const sessionStoragePersistor = createWebStoragePersistor({ storage: window.sessionStorage })
3232

3333
persistQueryClient({
3434
queryClient,
@@ -40,17 +40,15 @@ persistQueryClient({
4040

4141
### `createWebStoragePersistor`
4242

43-
Call this function (with an optional options object) to create a webStoragePersistor that you can use later with `persistQueryClient`.
43+
Call this function to create a webStoragePersistor that you can use later with `persistQueryClient`.
4444

4545
```js
46-
createWebStoragePersistor(options?: CreateWebStoragePersistorOptions)
46+
createWebStoragePersistor(options: CreateWebStoragePersistorOptions)
4747
```
4848

4949
### `Options`
5050

51-
An optional object of options:
52-
53-
```js
51+
```ts
5452
interface CreateWebStoragePersistorOptions {
5553
/** The storage client used for setting an retrieving items from cache (window.localStorage or window.sessionStorage) */
5654
storage: Storage

0 commit comments

Comments
 (0)