Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

README.md

38 lines1.1 KB

1# @tanstack/angular-query-persist-client
2​
3Persistence integration for `@tanstack/angular-query`.
4​
5## Installation
6​
7```sh
8pnpm add @tanstack/angular-query-persist-client @tanstack/query-async-storage-persister
9```
10​
11`@tanstack/query-async-storage-persister` provides the persister used below. Any
12other persister works as well.
13​
14## Usage
15​
16```ts
17import { QueryClient, provideTanStackQuery } from '@tanstack/angular-query'
18import { withPersistQueryClient } from '@tanstack/angular-query-persist-client'
19import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister'
20import type { ApplicationConfig } from '@angular/core'
21​
22export const appConfig: ApplicationConfig = {
23 providers: [
24 provideTanStackQuery(
25 () => new QueryClient(),
26 withPersistQueryClient(() => ({
27 persistOptions: {
28 persister: createAsyncStoragePersister({ storage: localStorage }),
29 },
30 })),
31 ),
32 ],
34```
35​
36The factory runs only in the browser and inside an Angular injection context.
37This makes it safe to access browser-only storage and inject application
38services without sharing persistence state between SSR requests.