Skip to content

Commit 3b15db1

Browse files
committed
feat: define const for queryClient injection
1 parent 760f9af commit 3b15db1

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ Vue bindings for [react-query](https://github.com/tannerlinsley/react-query)
1313
2. Attach vue-react-query to your Vue application
1414

1515
```
16-
import { QueryClient } from "vue-react-query";
16+
import { QueryClient, VUE_REACT_QUERY_CLIENT } from "vue-react-query";
1717
import { createApp } from "vue";
1818
import App from "./App.vue";
1919
2020
const app = createApp(App);
2121
const queryClient = new QueryClient();
2222
23-
app.provide("queryClient", queryClient);
23+
app.provide(VUE_REACT_QUERY_CLIENT, queryClient);
2424
2525
app.mount("#app");
2626
```

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export { QueryClient } from "react-query/core";
22

3-
export { useQueryClient } from "./useQueryClient";
3+
export { useQueryClient, VUE_REACT_QUERY_CLIENT } from "./useQueryClient";
44

55
export { useQuery } from "./useQuery";
66
export { useQueries } from "./useQueries";

src/useBaseQuery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function useBaseQuery<TQueryFnData, TError, TData, TQueryData>(
3737
unsubscribe();
3838
});
3939

40-
return (toRefs(readonly(state)) as unknown) as ToRefs<
40+
return toRefs(readonly(state)) as ToRefs<
4141
Readonly<UseQueryResult<TData, TError>>
4242
>;
4343
}

src/useQueries.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,5 @@ export function useQueries(
3333
unsubscribe();
3434
});
3535

36-
return (toRefs(readonly(state)) as unknown) as ToRefs<
37-
Readonly<UseQueryResult[]>
38-
>;
36+
return toRefs(readonly(state)) as ToRefs<Readonly<UseQueryResult[]>>;
3937
}

src/useQueryClient.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import { inject } from "vue";
22

33
import type { QueryClient } from "react-query/types";
44

5+
export const VUE_REACT_QUERY_CLIENT = "VUE_REACT_QUERY_CLIENT";
6+
57
export function useQueryClient(): QueryClient {
6-
const queryClient = inject<QueryClient>("queryClient");
8+
const queryClient = inject<QueryClient>(VUE_REACT_QUERY_CLIENT);
79

810
if (!queryClient) {
911
throw new Error(
10-
"No queryClient found in Vue context, use 'app.provide(\"queryClient\", queryClient);' to set one in root component."
12+
"No queryClient found in Vue context, use 'app.provide(VUE_REACT_QUERY_CLIENT, new QueryClient());' to set one in root component."
1113
);
1214
}
1315

0 commit comments

Comments
 (0)