@@ -4,32 +4,47 @@ Vue Query allows providing custom `QueryClient` for Vue context.
4
4
5
5
It might be handy when you need to create ` QueryClient ` beforehand to integrate it with other libraries that do not have access to the Vue context.
6
6
7
- For this reason, ` useQueryProvider ` accepts either QueryClient options or ` QueryClient ` as a first argument .
7
+ For this reason, ` VueQueryPlugin ` accepts either ` QueryClientConfig ` or ` QueryClient ` as a plugin options .
8
8
9
- If You provide QueryClient options , ` QueryClient ` instance will be created internally and provided to Vue context.
9
+ If You provide ` QueryClientConfig ` , ` QueryClient ` instance will be created internally and provided to Vue context.
10
10
11
- ``` js
12
- useQueryProvider (queryClientOptions);
11
+ ``` ts
12
+ const vueQueryPluginOptions: VueQueryPluginOptions = {
13
+ queryClientConfig: {
14
+ defaultOptions: { queries: { staleTime: 3600 } },
15
+ },
16
+ };
17
+ app .use (VueQueryPlugin , vueQueryPluginOptions );
13
18
```
14
19
15
- ``` js
16
- const myClient = new QueryClient (queryClientOptions);
17
- useQueryProvider (myClient);
20
+ ``` ts
21
+ const myClient = new QueryClient (queryClientConfig );
22
+ const vueQueryPluginOptions: VueQueryPluginOptions = {
23
+ queryClient: myClient ,
24
+ };
25
+ app .use (VueQueryPlugin , vueQueryPluginOptions );
18
26
```
19
27
20
28
### Custom context keys
21
29
22
30
You can also customize the key under which ` QueryClient ` will be accessible in Vue context. This can be usefull is you want to avoid name clashing between multiple apps on the same page.
23
31
24
- It works both with default, and custom provided ` QueryClient `
32
+ It works both with default, and custom ` QueryClient `
25
33
26
- ``` js
27
- useQueryProvider (queryClientOptions, " foo" );
34
+ ``` ts
35
+ const vueQueryPluginOptions: VueQueryPluginOptions = {
36
+ queryClientKey: " Foo" ,
37
+ };
38
+ app .use (VueQueryPlugin , vueQueryPluginOptions );
28
39
```
29
40
30
- ``` js
31
- const myClient = new QueryClient (queryClientOptions);
32
- useQueryProvider (myClient, " bar" );
41
+ ``` ts
42
+ const myClient = new QueryClient (queryClientConfig );
43
+ const vueQueryPluginOptions: VueQueryPluginOptions = {
44
+ queryClient: myClient ,
45
+ queryClientKey: " Foo" ,
46
+ };
47
+ app .use (VueQueryPlugin , vueQueryPluginOptions );
33
48
```
34
49
35
50
To use the custom client key, You have to provide it as a query options
@@ -48,6 +63,9 @@ Devtools also support this by the `queryClientKeys` prop. You can provide multip
48
63
49
64
Internally custom key will be combined with default query key as a suffix. But user do not have to worry about it.
50
65
51
- ``` js
52
- useQueryProvider (queryClientOptions, " foo" ); // -> VUE_QUERY_CLIENT:foo
66
+ ``` ts
67
+ const vueQueryPluginOptions: VueQueryPluginOptions = {
68
+ queryClientKey: " Foo" ,
69
+ };
70
+ app .use (VueQueryPlugin , vueQueryPluginOptions ); // -> VUE_QUERY_CLIENT:Foo
53
71
```
0 commit comments