You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/framework/react/plugins/createPersister.md
+68-15
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
id: createPersister
3
-
title: experimental_createPersister
3
+
title: experimental_createQueryPersister
4
4
---
5
5
6
6
## Installation
@@ -33,9 +33,9 @@ bun add @tanstack/query-persist-client-core
33
33
34
34
## Usage
35
35
36
-
- Import the `experimental_createPersister` function
37
-
- Create a new `experimental_createPersister`
38
-
- you can pass any `storage` to it that adheres to the `AsyncStorage`or `Storage`interface - the example below uses the async-storage from React Native.
36
+
- Import the `experimental_createQueryPersister` function
37
+
- Create a new `experimental_createQueryPersister`
38
+
- you can pass any `storage` to it that adheres to the `AsyncStorage` interface - the example below uses the async-storage from React Native.
39
39
- Pass that `persister` as an option to your Query. This can be done either by passing it to the `defaultOptions` of the `QueryClient` or to any `useQuery` hook instance.
40
40
- If you pass this `persister` as `defaultOptions`, all queries will be persisted to the provided `storage`. You can additionally narrow this down by passing `filters`. In contrast to the `persistClient` plugin, this will not persist the whole query client as a single item, but each query separately. As a key, the query hash is used.
41
41
- If you provide this `persister` to a single `useQuery` hook, only this Query will be persisted.
@@ -48,16 +48,18 @@ Garbage collecting a Query from memory **does not** affect the persisted data. T
@@ -67,12 +69,62 @@ const queryClient = new QueryClient({
67
69
68
70
The `createPersister` plugin technically wraps the `queryFn`, so it doesn't restore if the `queryFn` doesn't run. In that way, it acts as a caching layer between the Query and the network. Thus, the `networkMode` defaults to `'offlineFirst'` when a persister is used, so that restoring from the persistent storage can also happen even if there is no network connection.
69
71
72
+
## Additional utilities
73
+
74
+
Invoking `experimental_createQueryPersister` returns additional utilities in addition to `persisterFn` for easier implementation of userland functionalities.
This function can be used to restore all queries that are currently stored by persister in one go.
117
+
For example when your app is starting up in offline mode, or you want data from previous session to be immediately available without intermediate `loading` state.
118
+
119
+
For this function to work, your storage must expose `entries` method that would return a `key-value tuple array`.
120
+
For example `Object.entries(localStorage)` for `localStorage` or `entries` from `idb-keyval`.
Copy file name to clipboardExpand all lines: docs/framework/vue/plugins/createPersister.md
+12-10
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
id: createPersister
3
-
title: experimental_createPersister
3
+
title: experimental_createQueryPersister
4
4
---
5
5
6
6
## Installation
@@ -31,8 +31,8 @@ bun add @tanstack/query-persist-client-core
31
31
32
32
## Usage
33
33
34
-
- Import the `experimental_createPersister` function
35
-
- Create a new `experimental_createPersister`
34
+
- Import the `experimental_createQueryPersister` function
35
+
- Create a new `experimental_createQueryPersister`
36
36
- you can pass any `storage` to it that adheres to the `AsyncStorage` or `Storage` interface
37
37
- Pass that `persister` as an option to your Query. This can be done either by passing it to the `defaultOptions` of the `QueryClient` or to any `useQuery` hook instance.
38
38
- If you pass this `persister` as `defaultOptions`, all queries will be persisted to the provided `storage`. You can additionally narrow this down by passing `filters`. In contrast to the `persistClient` plugin, this will not persist the whole query client as a single item, but each query separately. As a key, the query hash is used.
@@ -44,16 +44,18 @@ Garbage collecting a Query from memory **does not** affect the persisted data. T
0 commit comments