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
+56-5Lines changed: 56 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ bun add @tanstack/query-persist-client-core
35
35
36
36
- Import the `experimental_createQueryPersister` function
37
37
- Create a new `experimental_createQueryPersister`
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.
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.
@@ -69,6 +69,56 @@ const queryClient = new QueryClient({
69
69
70
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.
71
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`.
0 commit comments