@@ -4,32 +4,47 @@ Vue Query allows providing custom `QueryClient` for Vue context.
44
55It 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.
66
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 .
88
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.
1010
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 );
1318```
1419
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 );
1826```
1927
2028### Custom context keys
2129
2230You 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.
2331
24- It works both with default, and custom provided ` QueryClient `
32+ It works both with default, and custom ` QueryClient `
2533
26- ``` js
27- useQueryProvider (queryClientOptions, " foo" );
34+ ``` ts
35+ const vueQueryPluginOptions: VueQueryPluginOptions = {
36+ queryClientKey: " Foo" ,
37+ };
38+ app .use (VueQueryPlugin , vueQueryPluginOptions );
2839```
2940
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 );
3348```
3449
3550To 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
4863
4964Internally custom key will be combined with default query key as a suffix. But user do not have to worry about it.
5065
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
5371```
0 commit comments