@tanstack/react-query 5.0.0-alpha.3 → 5.0.0-alpha.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/codemods/utils/index.js +205 -0
- package/build/codemods/utils/transformers/query-cache-transformer.js +116 -0
- package/build/codemods/utils/transformers/query-client-transformer.js +48 -0
- package/build/codemods/utils/transformers/use-query-like-transformer.js +32 -0
- package/build/codemods/v4/__testfixtures__/default-import.input.tsx +94 -0
- package/build/codemods/v4/__testfixtures__/default-import.output.tsx +96 -0
- package/build/codemods/v4/__testfixtures__/named-import.input.tsx +96 -0
- package/build/codemods/v4/__testfixtures__/named-import.output.tsx +98 -0
- package/build/codemods/v4/__testfixtures__/namespaced-import.input.tsx +86 -0
- package/build/codemods/v4/__testfixtures__/namespaced-import.output.tsx +88 -0
- package/build/codemods/v4/__testfixtures__/parameter-is-identifier.input.tsx +49 -0
- package/build/codemods/v4/__testfixtures__/parameter-is-identifier.output.tsx +49 -0
- package/build/codemods/v4/__testfixtures__/parameter-is-object-expression.input.tsx +128 -0
- package/build/codemods/v4/__testfixtures__/parameter-is-object-expression.output.tsx +175 -0
- package/build/codemods/v4/__testfixtures__/replace-import-specifier.input.tsx +10 -0
- package/build/codemods/v4/__testfixtures__/replace-import-specifier.output.tsx +10 -0
- package/build/codemods/v4/__testfixtures__/type-arguments.input.tsx +25 -0
- package/build/codemods/v4/__testfixtures__/type-arguments.output.tsx +31 -0
- package/build/codemods/v4/__tests__/key-transformation.test.js +32 -0
- package/build/codemods/v4/__tests__/replace-import-specifier.test.js +12 -0
- package/build/codemods/v4/key-transformation.js +138 -0
- package/build/codemods/v4/replace-import-specifier.js +25 -0
- package/build/codemods/v4/utils/replacers/key-replacer.js +164 -0
- package/build/codemods/v5/remove-overloads/__testfixtures__/default-import.input.tsx +199 -0
- package/build/codemods/v5/remove-overloads/__testfixtures__/default-import.output.tsx +484 -0
- package/build/codemods/v5/remove-overloads/__tests__/remove-overloads.test.js +6 -0
- package/build/codemods/v5/remove-overloads/remove-overloads.js +59 -0
- package/build/codemods/v5/remove-overloads/transformers/filter-aware-usage-transformer.js +153 -0
- package/build/codemods/v5/remove-overloads/transformers/query-fn-aware-usage-transformer.js +188 -0
- package/build/codemods/v5/remove-overloads/utils/index.js +124 -0
- package/build/codemods/v5/remove-overloads/utils/unknown-usage-error.js +26 -0
- package/build/lib/HydrationBoundary.d.ts +1 -0
- package/build/lib/HydrationBoundary.d.ts.map +1 -0
- package/build/lib/HydrationBoundary.esm.js +1 -0
- package/build/lib/HydrationBoundary.esm.js.map +1 -1
- package/build/lib/HydrationBoundary.js +1 -0
- package/build/lib/HydrationBoundary.js.map +1 -1
- package/build/lib/HydrationBoundary.mjs +1 -0
- package/build/lib/HydrationBoundary.mjs.map +1 -1
- package/build/lib/QueryClientProvider.d.ts +1 -0
- package/build/lib/QueryClientProvider.d.ts.map +1 -0
- package/build/lib/QueryClientProvider.esm.js +1 -0
- package/build/lib/QueryClientProvider.esm.js.map +1 -1
- package/build/lib/QueryClientProvider.js +1 -0
- package/build/lib/QueryClientProvider.js.map +1 -1
- package/build/lib/QueryClientProvider.mjs +1 -0
- package/build/lib/QueryClientProvider.mjs.map +1 -1
- package/build/lib/QueryErrorResetBoundary.d.ts +1 -0
- package/build/lib/QueryErrorResetBoundary.d.ts.map +1 -0
- package/build/lib/QueryErrorResetBoundary.esm.js +1 -0
- package/build/lib/QueryErrorResetBoundary.esm.js.map +1 -1
- package/build/lib/QueryErrorResetBoundary.js +1 -0
- package/build/lib/QueryErrorResetBoundary.js.map +1 -1
- package/build/lib/QueryErrorResetBoundary.mjs +1 -0
- package/build/lib/QueryErrorResetBoundary.mjs.map +1 -1
- package/build/lib/__tests__/HydrationBoundary.test.d.ts +1 -0
- package/build/lib/__tests__/HydrationBoundary.test.d.ts.map +1 -0
- package/build/lib/__tests__/QueryClientProvider.test.d.ts +1 -0
- package/build/lib/__tests__/QueryClientProvider.test.d.ts.map +1 -0
- package/build/lib/__tests__/QueryResetErrorBoundary.test.d.ts +1 -0
- package/build/lib/__tests__/QueryResetErrorBoundary.test.d.ts.map +1 -0
- package/build/lib/__tests__/ssr-hydration.test.d.ts +1 -0
- package/build/lib/__tests__/ssr-hydration.test.d.ts.map +1 -0
- package/build/lib/__tests__/ssr.test.d.ts +1 -3
- package/build/lib/__tests__/ssr.test.d.ts.map +1 -0
- package/build/lib/__tests__/suspense.test.d.ts +1 -0
- package/build/lib/__tests__/suspense.test.d.ts.map +1 -0
- package/build/lib/__tests__/useInfiniteQuery.test.d.ts +1 -0
- package/build/lib/__tests__/useInfiniteQuery.test.d.ts.map +1 -0
- package/build/lib/__tests__/useInfiniteQuery.type.test.d.ts +1 -0
- package/build/lib/__tests__/useInfiniteQuery.type.test.d.ts.map +1 -0
- package/build/lib/__tests__/useIsFetching.test.d.ts +1 -0
- package/build/lib/__tests__/useIsFetching.test.d.ts.map +1 -0
- package/build/lib/__tests__/useMutation.test.d.ts +1 -0
- package/build/lib/__tests__/useMutation.test.d.ts.map +1 -0
- package/build/lib/__tests__/useMutationState.test.d.ts +1 -0
- package/build/lib/__tests__/useMutationState.test.d.ts.map +1 -0
- package/build/lib/__tests__/useQueries.test.d.ts +1 -0
- package/build/lib/__tests__/useQueries.test.d.ts.map +1 -0
- package/build/lib/__tests__/useQuery.test.d.ts +1 -0
- package/build/lib/__tests__/useQuery.test.d.ts.map +1 -0
- package/build/lib/__tests__/useQuery.types.test.d.ts +1 -0
- package/build/lib/__tests__/useQuery.types.test.d.ts.map +1 -0
- package/build/lib/__tests__/utils.d.ts +3 -3
- package/build/lib/__tests__/utils.d.ts.map +1 -0
- package/build/lib/errorBoundaryUtils.d.ts +4 -3
- package/build/lib/errorBoundaryUtils.d.ts.map +1 -0
- package/build/lib/errorBoundaryUtils.esm.js +4 -3
- package/build/lib/errorBoundaryUtils.esm.js.map +1 -1
- package/build/lib/errorBoundaryUtils.js +4 -3
- package/build/lib/errorBoundaryUtils.js.map +1 -1
- package/build/lib/errorBoundaryUtils.mjs +4 -3
- package/build/lib/errorBoundaryUtils.mjs.map +1 -1
- package/build/lib/index.d.ts +2 -1
- package/build/lib/index.d.ts.map +1 -0
- package/build/lib/index.esm.js +1 -1
- package/build/lib/index.js +1 -0
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +1 -1
- package/build/lib/isRestoring.d.ts +1 -0
- package/build/lib/isRestoring.d.ts.map +1 -0
- package/build/lib/isRestoring.esm.js +1 -0
- package/build/lib/isRestoring.esm.js.map +1 -1
- package/build/lib/isRestoring.js +1 -0
- package/build/lib/isRestoring.js.map +1 -1
- package/build/lib/isRestoring.mjs +1 -0
- package/build/lib/isRestoring.mjs.map +1 -1
- package/build/lib/suspense.d.ts +2 -1
- package/build/lib/suspense.d.ts.map +1 -0
- package/build/lib/suspense.esm.js +2 -9
- package/build/lib/suspense.esm.js.map +1 -1
- package/build/lib/suspense.js +2 -9
- package/build/lib/suspense.js.map +1 -1
- package/build/lib/suspense.mjs +1 -8
- package/build/lib/suspense.mjs.map +1 -1
- package/build/lib/types.d.ts +1 -0
- package/build/lib/types.d.ts.map +1 -0
- package/build/lib/useBaseQuery.d.ts +1 -0
- package/build/lib/useBaseQuery.d.ts.map +1 -0
- package/build/lib/useBaseQuery.esm.js +2 -12
- package/build/lib/useBaseQuery.esm.js.map +1 -1
- package/build/lib/useBaseQuery.js +2 -12
- package/build/lib/useBaseQuery.js.map +1 -1
- package/build/lib/useBaseQuery.mjs +2 -12
- package/build/lib/useBaseQuery.mjs.map +1 -1
- package/build/lib/useInfiniteQuery.d.ts +1 -0
- package/build/lib/useInfiniteQuery.d.ts.map +1 -0
- package/build/lib/useInfiniteQuery.esm.js +1 -0
- package/build/lib/useInfiniteQuery.esm.js.map +1 -1
- package/build/lib/useInfiniteQuery.js +1 -0
- package/build/lib/useInfiniteQuery.js.map +1 -1
- package/build/lib/useInfiniteQuery.mjs +1 -0
- package/build/lib/useInfiniteQuery.mjs.map +1 -1
- package/build/lib/useIsFetching.d.ts +1 -0
- package/build/lib/useIsFetching.d.ts.map +1 -0
- package/build/lib/useIsFetching.esm.js +1 -0
- package/build/lib/useIsFetching.esm.js.map +1 -1
- package/build/lib/useIsFetching.js +1 -0
- package/build/lib/useIsFetching.js.map +1 -1
- package/build/lib/useIsFetching.mjs +1 -0
- package/build/lib/useIsFetching.mjs.map +1 -1
- package/build/lib/useMutation.d.ts +1 -0
- package/build/lib/useMutation.d.ts.map +1 -0
- package/build/lib/useMutation.esm.js +2 -1
- package/build/lib/useMutation.esm.js.map +1 -1
- package/build/lib/useMutation.js +2 -1
- package/build/lib/useMutation.js.map +1 -1
- package/build/lib/useMutation.mjs +2 -1
- package/build/lib/useMutation.mjs.map +1 -1
- package/build/lib/useMutationState.d.ts +4 -3
- package/build/lib/useMutationState.d.ts.map +1 -0
- package/build/lib/useMutationState.esm.js +1 -0
- package/build/lib/useMutationState.esm.js.map +1 -1
- package/build/lib/useMutationState.js +1 -0
- package/build/lib/useMutationState.js.map +1 -1
- package/build/lib/useMutationState.mjs +1 -0
- package/build/lib/useMutationState.mjs.map +1 -1
- package/build/lib/useQueries.d.ts +3 -3
- package/build/lib/useQueries.d.ts.map +1 -0
- package/build/lib/useQueries.esm.js +20 -16
- package/build/lib/useQueries.esm.js.map +1 -1
- package/build/lib/useQueries.js +20 -16
- package/build/lib/useQueries.js.map +1 -1
- package/build/lib/useQueries.mjs +12 -11
- package/build/lib/useQueries.mjs.map +1 -1
- package/build/lib/useQuery.d.ts +3 -0
- package/build/lib/useQuery.d.ts.map +1 -0
- package/build/lib/useQuery.esm.js +6 -1
- package/build/lib/useQuery.esm.js.map +1 -1
- package/build/lib/useQuery.js +6 -0
- package/build/lib/useQuery.js.map +1 -1
- package/build/lib/useQuery.mjs +6 -1
- package/build/lib/useQuery.mjs.map +1 -1
- package/build/lib/utils.d.ts +1 -0
- package/build/lib/utils.d.ts.map +1 -0
- package/build/umd/index.development.js +124 -155
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +9 -4
- package/src/__tests__/HydrationBoundary.test.tsx +4 -3
- package/src/__tests__/QueryClientProvider.test.tsx +2 -1
- package/src/__tests__/QueryResetErrorBoundary.test.tsx +753 -620
- package/src/__tests__/ssr-hydration.test.tsx +11 -10
- package/src/__tests__/ssr.test.tsx +4 -7
- package/src/__tests__/suspense.test.tsx +17 -98
- package/src/__tests__/useInfiniteQuery.test.tsx +18 -16
- package/src/__tests__/useInfiniteQuery.type.test.tsx +94 -13
- package/src/__tests__/useMutation.test.tsx +25 -24
- package/src/__tests__/useMutationState.test.tsx +24 -58
- package/src/__tests__/useQueries.test.tsx +34 -163
- package/src/__tests__/useQuery.test.tsx +234 -365
- package/src/__tests__/useQuery.types.test.tsx +21 -1
- package/src/__tests__/utils.tsx +3 -2
- package/src/errorBoundaryUtils.ts +6 -5
- package/src/index.ts +1 -1
- package/src/suspense.ts +3 -11
- package/src/useBaseQuery.ts +2 -20
- package/src/useInfiniteQuery.ts +1 -0
- package/src/useIsFetching.ts +1 -0
- package/src/useMutation.ts +2 -1
- package/src/useMutationState.ts +4 -3
- package/src/useQueries.ts +20 -19
- package/src/useQuery.ts +23 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import {
|
|
3
|
+
QueryCache as RenamedQueryCache,
|
|
4
|
+
QueryClient as RenamedQueryClient,
|
|
5
|
+
useInfiniteQuery as useRenamedInfiniteQuery,
|
|
6
|
+
useIsFetching as useRenamedIsFetching,
|
|
7
|
+
useIsMutating as useRenamedIsMutating,
|
|
8
|
+
useMutation as useRenamedMutation,
|
|
9
|
+
useQueries as useRenamedQueries,
|
|
10
|
+
useQuery as useRenamedQuery,
|
|
11
|
+
useQueryClient as useRenamedQueryClient,
|
|
12
|
+
} from 'react-query'
|
|
13
|
+
|
|
14
|
+
export const Examples = () => {
|
|
15
|
+
useRenamedQuery(['todos'])
|
|
16
|
+
useRenamedInfiniteQuery(['todos'])
|
|
17
|
+
useRenamedMutation(['todos'])
|
|
18
|
+
useRenamedIsFetching(['todos'])
|
|
19
|
+
useRenamedIsMutating(['todos'])
|
|
20
|
+
useRenamedQueries({
|
|
21
|
+
queries: [query1, query2]
|
|
22
|
+
})
|
|
23
|
+
// QueryClient methods
|
|
24
|
+
// --- Instantiated hook call.
|
|
25
|
+
const queryClient = useRenamedQueryClient()
|
|
26
|
+
queryClient.getMutationDefaults(['todos'])
|
|
27
|
+
queryClient.getQueriesData(['todos'])
|
|
28
|
+
queryClient.getQueryData(['todos'])
|
|
29
|
+
queryClient.getQueryDefaults(['todos'])
|
|
30
|
+
queryClient.getQueryState(['todos'])
|
|
31
|
+
queryClient.isFetching(['todos'])
|
|
32
|
+
queryClient.setMutationDefaults(['todos'], { mutationFn: async () => null })
|
|
33
|
+
queryClient.setQueriesData(['todos'], () => null)
|
|
34
|
+
queryClient.setQueryData(['todos'], () => null)
|
|
35
|
+
queryClient.setQueryDefaults(['todos'], { queryFn: async () => null })
|
|
36
|
+
queryClient.cancelQueries(['todos'])
|
|
37
|
+
queryClient.fetchInfiniteQuery(['todos'])
|
|
38
|
+
queryClient.fetchQuery(['todos'])
|
|
39
|
+
queryClient.invalidateQueries(['todos'])
|
|
40
|
+
queryClient.prefetchInfiniteQuery(['todos'])
|
|
41
|
+
queryClient.prefetchQuery(['todos'])
|
|
42
|
+
queryClient.refetchQueries(['todos'])
|
|
43
|
+
queryClient.removeQueries(['todos'])
|
|
44
|
+
queryClient.resetQueries(['todos'])
|
|
45
|
+
// --- Direct hook call.
|
|
46
|
+
useRenamedQueryClient().getMutationDefaults(['todos'])
|
|
47
|
+
useRenamedQueryClient().getQueriesData(['todos'])
|
|
48
|
+
useRenamedQueryClient().getQueryData(['todos'])
|
|
49
|
+
useRenamedQueryClient().getQueryDefaults(['todos'])
|
|
50
|
+
useRenamedQueryClient().getQueryState(['todos'])
|
|
51
|
+
useRenamedQueryClient().isFetching(['todos'])
|
|
52
|
+
useRenamedQueryClient().setMutationDefaults(['todos'], {
|
|
53
|
+
mutationFn: async () => null,
|
|
54
|
+
})
|
|
55
|
+
useRenamedQueryClient().setQueriesData(['todos'], () => null)
|
|
56
|
+
useRenamedQueryClient().setQueryData(['todos'], () => null)
|
|
57
|
+
useRenamedQueryClient().setQueryDefaults(['todos'], {
|
|
58
|
+
queryFn: async () => null,
|
|
59
|
+
})
|
|
60
|
+
useRenamedQueryClient().cancelQueries(['todos'])
|
|
61
|
+
useRenamedQueryClient().fetchInfiniteQuery(['todos'])
|
|
62
|
+
useRenamedQueryClient().fetchQuery(['todos'])
|
|
63
|
+
useRenamedQueryClient().invalidateQueries(['todos'])
|
|
64
|
+
useRenamedQueryClient().prefetchInfiniteQuery(['todos'])
|
|
65
|
+
useRenamedQueryClient().prefetchQuery(['todos'])
|
|
66
|
+
useRenamedQueryClient().refetchQueries(['todos'])
|
|
67
|
+
useRenamedQueryClient().removeQueries(['todos'])
|
|
68
|
+
useRenamedQueryClient().resetQueries(['todos'])
|
|
69
|
+
// QueryCache
|
|
70
|
+
// --- NewExpression
|
|
71
|
+
const queryCache1 = new RenamedQueryCache({
|
|
72
|
+
onError: (error) => console.log(error),
|
|
73
|
+
onSuccess: (success) => console.log(success)
|
|
74
|
+
})
|
|
75
|
+
queryCache1.find(['todos'])
|
|
76
|
+
queryCache1.findAll(['todos'])
|
|
77
|
+
// --- Instantiated hook call.
|
|
78
|
+
const queryClient1 = useRenamedQueryClient()
|
|
79
|
+
queryClient1.getQueryCache().find(['todos'])
|
|
80
|
+
queryClient1.getQueryCache().findAll(['todos'])
|
|
81
|
+
//
|
|
82
|
+
const queryClient2 = new RenamedQueryClient({})
|
|
83
|
+
queryClient2.getQueryCache().find(['todos'])
|
|
84
|
+
queryClient2.getQueryCache().findAll(['todos'])
|
|
85
|
+
//
|
|
86
|
+
const queryCache2 = queryClient1.getQueryCache()
|
|
87
|
+
queryCache2.find(['todos'])
|
|
88
|
+
queryCache2.findAll(['todos'])
|
|
89
|
+
// --- Direct hook call.
|
|
90
|
+
useRenamedQueryClient().getQueryCache().find(['todos'])
|
|
91
|
+
useRenamedQueryClient().getQueryCache().findAll(['todos'])
|
|
92
|
+
//
|
|
93
|
+
const queryCache3 = useRenamedQueryClient().getQueryCache()
|
|
94
|
+
queryCache3.find(['todos'])
|
|
95
|
+
queryCache3.findAll(['todos'])
|
|
96
|
+
|
|
97
|
+
return <div>Example Component</div>
|
|
98
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import * as RQ from 'react-query'
|
|
3
|
+
|
|
4
|
+
export const Examples = () => {
|
|
5
|
+
RQ.useQuery('todos')
|
|
6
|
+
RQ.useInfiniteQuery('todos')
|
|
7
|
+
RQ.useMutation('todos')
|
|
8
|
+
RQ.useIsFetching('todos')
|
|
9
|
+
RQ.useIsMutating('todos')
|
|
10
|
+
RQ.useQueries([query1, query2])
|
|
11
|
+
// QueryClient methods
|
|
12
|
+
// --- Instantiated hook call.
|
|
13
|
+
const queryClient = RQ.useQueryClient()
|
|
14
|
+
queryClient.getMutationDefaults('todos')
|
|
15
|
+
queryClient.getQueriesData('todos')
|
|
16
|
+
queryClient.getQueryData('todos')
|
|
17
|
+
queryClient.getQueryDefaults('todos')
|
|
18
|
+
queryClient.getQueryState('todos')
|
|
19
|
+
queryClient.isFetching('todos')
|
|
20
|
+
queryClient.setMutationDefaults('todos', { mutationFn: async () => null })
|
|
21
|
+
queryClient.setQueriesData('todos', () => null)
|
|
22
|
+
queryClient.setQueryData('todos', () => null)
|
|
23
|
+
queryClient.setQueryDefaults('todos', { queryFn: async () => null })
|
|
24
|
+
queryClient.cancelQueries('todos')
|
|
25
|
+
queryClient.fetchInfiniteQuery('todos')
|
|
26
|
+
queryClient.fetchQuery('todos')
|
|
27
|
+
queryClient.invalidateQueries('todos')
|
|
28
|
+
queryClient.prefetchInfiniteQuery('todos')
|
|
29
|
+
queryClient.prefetchQuery('todos')
|
|
30
|
+
queryClient.refetchQueries('todos')
|
|
31
|
+
queryClient.removeQueries('todos')
|
|
32
|
+
queryClient.resetQueries('todos')
|
|
33
|
+
// --- Direct hook call.
|
|
34
|
+
RQ.useQueryClient().getMutationDefaults('todos')
|
|
35
|
+
RQ.useQueryClient().getQueriesData('todos')
|
|
36
|
+
RQ.useQueryClient().getQueryData('todos')
|
|
37
|
+
RQ.useQueryClient().getQueryDefaults('todos')
|
|
38
|
+
RQ.useQueryClient().getQueryState('todos')
|
|
39
|
+
RQ.useQueryClient().isFetching('todos')
|
|
40
|
+
RQ.useQueryClient().setMutationDefaults('todos', {
|
|
41
|
+
mutationFn: async () => null,
|
|
42
|
+
})
|
|
43
|
+
RQ.useQueryClient().setQueriesData('todos', () => null)
|
|
44
|
+
RQ.useQueryClient().setQueryData('todos', () => null)
|
|
45
|
+
RQ.useQueryClient().setQueryDefaults('todos', {
|
|
46
|
+
queryFn: async () => null,
|
|
47
|
+
})
|
|
48
|
+
RQ.useQueryClient().cancelQueries('todos')
|
|
49
|
+
RQ.useQueryClient().fetchInfiniteQuery('todos')
|
|
50
|
+
RQ.useQueryClient().fetchQuery('todos')
|
|
51
|
+
RQ.useQueryClient().invalidateQueries('todos')
|
|
52
|
+
RQ.useQueryClient().prefetchInfiniteQuery('todos')
|
|
53
|
+
RQ.useQueryClient().prefetchQuery('todos')
|
|
54
|
+
RQ.useQueryClient().refetchQueries('todos')
|
|
55
|
+
RQ.useQueryClient().removeQueries('todos')
|
|
56
|
+
RQ.useQueryClient().resetQueries('todos')
|
|
57
|
+
// QueryCache
|
|
58
|
+
// --- NewExpression
|
|
59
|
+
const queryCache1 = new RQ.QueryCache({
|
|
60
|
+
onError: (error) => console.log(error),
|
|
61
|
+
onSuccess: (success) => console.log(success)
|
|
62
|
+
})
|
|
63
|
+
queryCache1.find('todos')
|
|
64
|
+
queryCache1.findAll('todos')
|
|
65
|
+
// --- Instantiated hook call.
|
|
66
|
+
const queryClient1 = RQ.useQueryClient()
|
|
67
|
+
queryClient1.getQueryCache().find('todos')
|
|
68
|
+
queryClient1.getQueryCache().findAll('todos')
|
|
69
|
+
//
|
|
70
|
+
const queryClient2 = new RQ.QueryClient({})
|
|
71
|
+
queryClient2.getQueryCache().find('todos')
|
|
72
|
+
queryClient2.getQueryCache().findAll('todos')
|
|
73
|
+
//
|
|
74
|
+
const queryCache2 = queryClient1.getQueryCache()
|
|
75
|
+
queryCache2.find('todos')
|
|
76
|
+
queryCache2.findAll('todos')
|
|
77
|
+
// --- Direct hook call.
|
|
78
|
+
RQ.useQueryClient().getQueryCache().find('todos')
|
|
79
|
+
RQ.useQueryClient().getQueryCache().findAll('todos')
|
|
80
|
+
//
|
|
81
|
+
const queryCache3 = RQ.useQueryClient().getQueryCache()
|
|
82
|
+
queryCache3.find('todos')
|
|
83
|
+
queryCache3.findAll('todos')
|
|
84
|
+
|
|
85
|
+
return <div>Example Component</div>
|
|
86
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import * as RQ from 'react-query'
|
|
3
|
+
|
|
4
|
+
export const Examples = () => {
|
|
5
|
+
RQ.useQuery(['todos'])
|
|
6
|
+
RQ.useInfiniteQuery(['todos'])
|
|
7
|
+
RQ.useMutation(['todos'])
|
|
8
|
+
RQ.useIsFetching(['todos'])
|
|
9
|
+
RQ.useIsMutating(['todos'])
|
|
10
|
+
RQ.useQueries({
|
|
11
|
+
queries: [query1, query2]
|
|
12
|
+
})
|
|
13
|
+
// QueryClient methods
|
|
14
|
+
// --- Instantiated hook call.
|
|
15
|
+
const queryClient = RQ.useQueryClient()
|
|
16
|
+
queryClient.getMutationDefaults(['todos'])
|
|
17
|
+
queryClient.getQueriesData(['todos'])
|
|
18
|
+
queryClient.getQueryData(['todos'])
|
|
19
|
+
queryClient.getQueryDefaults(['todos'])
|
|
20
|
+
queryClient.getQueryState(['todos'])
|
|
21
|
+
queryClient.isFetching(['todos'])
|
|
22
|
+
queryClient.setMutationDefaults(['todos'], { mutationFn: async () => null })
|
|
23
|
+
queryClient.setQueriesData(['todos'], () => null)
|
|
24
|
+
queryClient.setQueryData(['todos'], () => null)
|
|
25
|
+
queryClient.setQueryDefaults(['todos'], { queryFn: async () => null })
|
|
26
|
+
queryClient.cancelQueries(['todos'])
|
|
27
|
+
queryClient.fetchInfiniteQuery(['todos'])
|
|
28
|
+
queryClient.fetchQuery(['todos'])
|
|
29
|
+
queryClient.invalidateQueries(['todos'])
|
|
30
|
+
queryClient.prefetchInfiniteQuery(['todos'])
|
|
31
|
+
queryClient.prefetchQuery(['todos'])
|
|
32
|
+
queryClient.refetchQueries(['todos'])
|
|
33
|
+
queryClient.removeQueries(['todos'])
|
|
34
|
+
queryClient.resetQueries(['todos'])
|
|
35
|
+
// --- Direct hook call.
|
|
36
|
+
RQ.useQueryClient().getMutationDefaults(['todos'])
|
|
37
|
+
RQ.useQueryClient().getQueriesData(['todos'])
|
|
38
|
+
RQ.useQueryClient().getQueryData(['todos'])
|
|
39
|
+
RQ.useQueryClient().getQueryDefaults(['todos'])
|
|
40
|
+
RQ.useQueryClient().getQueryState(['todos'])
|
|
41
|
+
RQ.useQueryClient().isFetching(['todos'])
|
|
42
|
+
RQ.useQueryClient().setMutationDefaults(['todos'], {
|
|
43
|
+
mutationFn: async () => null,
|
|
44
|
+
})
|
|
45
|
+
RQ.useQueryClient().setQueriesData(['todos'], () => null)
|
|
46
|
+
RQ.useQueryClient().setQueryData(['todos'], () => null)
|
|
47
|
+
RQ.useQueryClient().setQueryDefaults(['todos'], {
|
|
48
|
+
queryFn: async () => null,
|
|
49
|
+
})
|
|
50
|
+
RQ.useQueryClient().cancelQueries(['todos'])
|
|
51
|
+
RQ.useQueryClient().fetchInfiniteQuery(['todos'])
|
|
52
|
+
RQ.useQueryClient().fetchQuery(['todos'])
|
|
53
|
+
RQ.useQueryClient().invalidateQueries(['todos'])
|
|
54
|
+
RQ.useQueryClient().prefetchInfiniteQuery(['todos'])
|
|
55
|
+
RQ.useQueryClient().prefetchQuery(['todos'])
|
|
56
|
+
RQ.useQueryClient().refetchQueries(['todos'])
|
|
57
|
+
RQ.useQueryClient().removeQueries(['todos'])
|
|
58
|
+
RQ.useQueryClient().resetQueries(['todos'])
|
|
59
|
+
// QueryCache
|
|
60
|
+
// --- NewExpression
|
|
61
|
+
const queryCache1 = new RQ.QueryCache({
|
|
62
|
+
onError: (error) => console.log(error),
|
|
63
|
+
onSuccess: (success) => console.log(success)
|
|
64
|
+
})
|
|
65
|
+
queryCache1.find(['todos'])
|
|
66
|
+
queryCache1.findAll(['todos'])
|
|
67
|
+
// --- Instantiated hook call.
|
|
68
|
+
const queryClient1 = RQ.useQueryClient()
|
|
69
|
+
queryClient1.getQueryCache().find(['todos'])
|
|
70
|
+
queryClient1.getQueryCache().findAll(['todos'])
|
|
71
|
+
//
|
|
72
|
+
const queryClient2 = new RQ.QueryClient({})
|
|
73
|
+
queryClient2.getQueryCache().find(['todos'])
|
|
74
|
+
queryClient2.getQueryCache().findAll(['todos'])
|
|
75
|
+
//
|
|
76
|
+
const queryCache2 = queryClient1.getQueryCache()
|
|
77
|
+
queryCache2.find(['todos'])
|
|
78
|
+
queryCache2.findAll(['todos'])
|
|
79
|
+
// --- Direct hook call.
|
|
80
|
+
RQ.useQueryClient().getQueryCache().find(['todos'])
|
|
81
|
+
RQ.useQueryClient().getQueryCache().findAll(['todos'])
|
|
82
|
+
//
|
|
83
|
+
const queryCache3 = RQ.useQueryClient().getQueryCache()
|
|
84
|
+
queryCache3.find(['todos'])
|
|
85
|
+
queryCache3.findAll(['todos'])
|
|
86
|
+
|
|
87
|
+
return <div>Example Component</div>
|
|
88
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { useMutation, useQuery, useQueryClient } from 'react-query'
|
|
3
|
+
|
|
4
|
+
export const ExampleWithStringLiteralKey = () => {
|
|
5
|
+
const stringLiteralKey = 'todos'
|
|
6
|
+
useQuery(stringLiteralKey)
|
|
7
|
+
useMutation(stringLiteralKey)
|
|
8
|
+
// QueryClient methods
|
|
9
|
+
// --- Instantiated hook call.
|
|
10
|
+
const queryClient = useQueryClient()
|
|
11
|
+
queryClient.cancelQueries(stringLiteralKey)
|
|
12
|
+
// --- Direct hook call.
|
|
13
|
+
useQueryClient().cancelQueries(stringLiteralKey)
|
|
14
|
+
|
|
15
|
+
return <div>Example Component</div>
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const ExampleWithTemplateLiteral = () => {
|
|
19
|
+
const templateLiteralKey = `todos`
|
|
20
|
+
useQuery(templateLiteralKey)
|
|
21
|
+
useMutation(templateLiteralKey)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const ExampleWithArrayExpressionKey = () => {
|
|
25
|
+
const arrayExpressionKey = ['todos']
|
|
26
|
+
useQuery(arrayExpressionKey)
|
|
27
|
+
useMutation(arrayExpressionKey)
|
|
28
|
+
// QueryClient methods
|
|
29
|
+
// --- Instantiated hook call.
|
|
30
|
+
const queryClient = useQueryClient()
|
|
31
|
+
queryClient.cancelQueries(queryKey2)
|
|
32
|
+
// --- Direct hook call.
|
|
33
|
+
useQueryClient().cancelQueries(queryKey2)
|
|
34
|
+
|
|
35
|
+
return <div>Example Component</div>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const ExampleWithUnknownKey = () => {
|
|
39
|
+
useQuery(unknownQueryKey)
|
|
40
|
+
useMutation(unknownQueryKey)
|
|
41
|
+
// QueryClient methods
|
|
42
|
+
// --- Instantiated hook call.
|
|
43
|
+
const queryClient = useQueryClient()
|
|
44
|
+
queryClient.cancelQueries(unknownQueryKey)
|
|
45
|
+
// --- Direct hook call.
|
|
46
|
+
useQueryClient().cancelQueries(unknownQueryKey)
|
|
47
|
+
|
|
48
|
+
return <div>Example Component</div>
|
|
49
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { useMutation, useQuery, useQueryClient } from 'react-query'
|
|
3
|
+
|
|
4
|
+
export const ExampleWithStringLiteralKey = () => {
|
|
5
|
+
const stringLiteralKey = 'todos'
|
|
6
|
+
useQuery([stringLiteralKey])
|
|
7
|
+
useMutation([stringLiteralKey])
|
|
8
|
+
// QueryClient methods
|
|
9
|
+
// --- Instantiated hook call.
|
|
10
|
+
const queryClient = useQueryClient()
|
|
11
|
+
queryClient.cancelQueries([stringLiteralKey])
|
|
12
|
+
// --- Direct hook call.
|
|
13
|
+
useQueryClient().cancelQueries([stringLiteralKey])
|
|
14
|
+
|
|
15
|
+
return <div>Example Component</div>
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const ExampleWithTemplateLiteral = () => {
|
|
19
|
+
const templateLiteralKey = `todos`
|
|
20
|
+
useQuery([templateLiteralKey])
|
|
21
|
+
useMutation([templateLiteralKey])
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const ExampleWithArrayExpressionKey = () => {
|
|
25
|
+
const arrayExpressionKey = ['todos']
|
|
26
|
+
useQuery(arrayExpressionKey)
|
|
27
|
+
useMutation(arrayExpressionKey)
|
|
28
|
+
// QueryClient methods
|
|
29
|
+
// --- Instantiated hook call.
|
|
30
|
+
const queryClient = useQueryClient()
|
|
31
|
+
queryClient.cancelQueries(queryKey2)
|
|
32
|
+
// --- Direct hook call.
|
|
33
|
+
useQueryClient().cancelQueries(queryKey2)
|
|
34
|
+
|
|
35
|
+
return <div>Example Component</div>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const ExampleWithUnknownKey = () => {
|
|
39
|
+
useQuery(unknownQueryKey)
|
|
40
|
+
useMutation(unknownQueryKey)
|
|
41
|
+
// QueryClient methods
|
|
42
|
+
// --- Instantiated hook call.
|
|
43
|
+
const queryClient = useQueryClient()
|
|
44
|
+
queryClient.cancelQueries(unknownQueryKey)
|
|
45
|
+
// --- Direct hook call.
|
|
46
|
+
useQueryClient().cancelQueries(unknownQueryKey)
|
|
47
|
+
|
|
48
|
+
return <div>Example Component</div>
|
|
49
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { useMutation, useQuery, useQueryClient } from 'react-query'
|
|
3
|
+
|
|
4
|
+
const options = {}
|
|
5
|
+
|
|
6
|
+
export const ExampleWithStringLiteral = () => {
|
|
7
|
+
useQuery({ queryKey: 'todos', exact: true }, options)
|
|
8
|
+
useMutation({ mutationKey: 'todos', exact: true }, options)
|
|
9
|
+
// QueryClient methods
|
|
10
|
+
// --- Instantiated hook call.
|
|
11
|
+
const queryClient = useQueryClient()
|
|
12
|
+
queryClient.cancelQueries({ queryKey: 'todos', exact: true }, options)
|
|
13
|
+
// --- Direct hook call.
|
|
14
|
+
useQueryClient().cancelQueries({ queryKey: 'todos', exact: true }, options)
|
|
15
|
+
|
|
16
|
+
return <div>Example Component</div>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const ExampleWithStringLiteralIdentifier = () => {
|
|
20
|
+
const stringLiteralKey = 'todos'
|
|
21
|
+
useQuery({ queryKey: stringLiteralKey, exact: true }, options)
|
|
22
|
+
useMutation({ mutationKey: stringLiteralKey, exact: true }, options)
|
|
23
|
+
// QueryClient methods
|
|
24
|
+
// --- Instantiated hook call.
|
|
25
|
+
const queryClient = useQueryClient()
|
|
26
|
+
queryClient.cancelQueries({ queryKey: stringLiteralKey, exact: true }, options)
|
|
27
|
+
// --- Direct hook call.
|
|
28
|
+
useQueryClient().cancelQueries({ queryKey: stringLiteralKey, exact: true }, options)
|
|
29
|
+
|
|
30
|
+
return <div>Example Component</div>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const ExampleWithTemplateLiteral = () => {
|
|
34
|
+
useQuery({ queryKey: `todos`, exact: true }, options)
|
|
35
|
+
useMutation({ mutationKey: `todos`, exact: true }, options)
|
|
36
|
+
// QueryClient methods
|
|
37
|
+
// --- Instantiated hook call.
|
|
38
|
+
const queryClient = useQueryClient()
|
|
39
|
+
queryClient.cancelQueries({ queryKey: `todos`, exact: true }, options)
|
|
40
|
+
// --- Direct hook call.
|
|
41
|
+
useQueryClient().cancelQueries({ queryKey: `todos`, exact: true }, options)
|
|
42
|
+
|
|
43
|
+
return <div>Example Component</div>
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const ExampleWithTemplateLiteralIdentifier = () => {
|
|
47
|
+
const templateLiteralKey = `todos`
|
|
48
|
+
useQuery({ queryKey: templateLiteralKey, exact: true }, options)
|
|
49
|
+
useMutation({ mutationKey: templateLiteralKey, exact: true }, options)
|
|
50
|
+
// QueryClient methods
|
|
51
|
+
// --- Instantiated hook call.
|
|
52
|
+
const queryClient = useQueryClient()
|
|
53
|
+
queryClient.cancelQueries({ queryKey: templateLiteralKey, exact: true }, options)
|
|
54
|
+
// --- Direct hook call.
|
|
55
|
+
useQueryClient().cancelQueries({ queryKey: templateLiteralKey, exact: true }, options)
|
|
56
|
+
|
|
57
|
+
return <div>Example Component</div>
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const ExampleWithArrayExpression = () => {
|
|
61
|
+
useQuery({ queryKey: ['todos'], exact: true }, options)
|
|
62
|
+
useMutation({ mutationKey: ['todos'], exact: true }, options)
|
|
63
|
+
// QueryClient methods
|
|
64
|
+
// --- Instantiated hook call.
|
|
65
|
+
const queryClient = useQueryClient()
|
|
66
|
+
queryClient.cancelQueries({ queryKey: ['todos'], exact: true }, options)
|
|
67
|
+
// --- Direct hook call.
|
|
68
|
+
useQueryClient().cancelQueries({ queryKey: ['todos'], exact: true }, options)
|
|
69
|
+
|
|
70
|
+
return <div>Example Component</div>
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const ExampleWithArrayExpressionIdentifier = () => {
|
|
74
|
+
const arrayExpressionKey = ['todos']
|
|
75
|
+
useQuery({ queryKey: arrayExpressionKey, exact: true }, options)
|
|
76
|
+
useMutation({ mutationKey: arrayExpressionKey, exact: true }, options)
|
|
77
|
+
// QueryClient methods
|
|
78
|
+
// --- Instantiated hook call.
|
|
79
|
+
const queryClient = useQueryClient()
|
|
80
|
+
queryClient.cancelQueries({ queryKey: arrayExpressionKey, exact: true }, options)
|
|
81
|
+
// --- Direct hook call.
|
|
82
|
+
useQueryClient().cancelQueries({ queryKey: arrayExpressionKey, exact: true }, options)
|
|
83
|
+
|
|
84
|
+
return <div>Example Component</div>
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const ExampleWithUnknownIdentifier1 = () => {
|
|
88
|
+
const createKey = (id) => ['todos', id]
|
|
89
|
+
const createdKey1 = createKey(1)
|
|
90
|
+
useQuery({ queryKey: createdKey1, exact: true }, options)
|
|
91
|
+
useMutation({ mutationKey: createdKey1, exact: true }, options)
|
|
92
|
+
// QueryClient methods
|
|
93
|
+
// --- Instantiated hook call.
|
|
94
|
+
const queryClient = useQueryClient()
|
|
95
|
+
queryClient.cancelQueries({ queryKey: createdKey1, exact: true }, options)
|
|
96
|
+
// --- Direct hook call.
|
|
97
|
+
useQueryClient().cancelQueries({ queryKey: createdKey1, exact: true }, options)
|
|
98
|
+
|
|
99
|
+
return <div>Example Component</div>
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const ExampleWithUnknownIdentifier2 = () => {
|
|
103
|
+
const createdKey2 = createKey()
|
|
104
|
+
useQuery({ queryKey: createdKey2, exact: true }, options)
|
|
105
|
+
useMutation({ mutationKey: createdKey2, exact: true }, options)
|
|
106
|
+
// QueryClient methods
|
|
107
|
+
// --- Instantiated hook call.
|
|
108
|
+
const queryClient = useQueryClient()
|
|
109
|
+
queryClient.cancelQueries({ queryKey: createdKey2, exact: true }, options)
|
|
110
|
+
// --- Direct hook call.
|
|
111
|
+
useQueryClient().cancelQueries({ queryKey: createdKey2, exact: true }, options)
|
|
112
|
+
|
|
113
|
+
return <div>Example Component</div>
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export const ExampleWithUnknownIdentifier3 = () => {
|
|
117
|
+
useQuery({ queryKey: unknownQueryKey, exact: true }, options)
|
|
118
|
+
useMutation({ mutationKey: unknownQueryKey, exact: true }, options)
|
|
119
|
+
// QueryClient methods
|
|
120
|
+
// --- Instantiated hook call.
|
|
121
|
+
const queryClient = useQueryClient()
|
|
122
|
+
queryClient.cancelQueries({ queryKey: unknownQueryKey, exact: true }, options)
|
|
123
|
+
// --- Direct hook call.
|
|
124
|
+
useQueryClient().cancelQueries({ queryKey: unknownQueryKey, exact: true }, options)
|
|
125
|
+
|
|
126
|
+
return <div>Example Component</div>
|
|
127
|
+
}
|
|
128
|
+
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { useMutation, useQuery, useQueryClient } from 'react-query'
|
|
3
|
+
|
|
4
|
+
const options = {}
|
|
5
|
+
|
|
6
|
+
export const ExampleWithStringLiteral = () => {
|
|
7
|
+
useQuery({
|
|
8
|
+
queryKey: ['todos'],
|
|
9
|
+
exact: true
|
|
10
|
+
}, options)
|
|
11
|
+
useMutation({
|
|
12
|
+
mutationKey: ['todos'],
|
|
13
|
+
exact: true
|
|
14
|
+
}, options)
|
|
15
|
+
// QueryClient methods
|
|
16
|
+
// --- Instantiated hook call.
|
|
17
|
+
const queryClient = useQueryClient()
|
|
18
|
+
queryClient.cancelQueries({
|
|
19
|
+
queryKey: ['todos'],
|
|
20
|
+
exact: true
|
|
21
|
+
}, options)
|
|
22
|
+
// --- Direct hook call.
|
|
23
|
+
useQueryClient().cancelQueries({
|
|
24
|
+
queryKey: ['todos'],
|
|
25
|
+
exact: true
|
|
26
|
+
}, options)
|
|
27
|
+
|
|
28
|
+
return <div>Example Component</div>
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const ExampleWithStringLiteralIdentifier = () => {
|
|
32
|
+
const stringLiteralKey = 'todos'
|
|
33
|
+
useQuery({
|
|
34
|
+
queryKey: [stringLiteralKey],
|
|
35
|
+
exact: true
|
|
36
|
+
}, options)
|
|
37
|
+
useMutation({
|
|
38
|
+
mutationKey: [stringLiteralKey],
|
|
39
|
+
exact: true
|
|
40
|
+
}, options)
|
|
41
|
+
// QueryClient methods
|
|
42
|
+
// --- Instantiated hook call.
|
|
43
|
+
const queryClient = useQueryClient()
|
|
44
|
+
queryClient.cancelQueries({
|
|
45
|
+
queryKey: [stringLiteralKey],
|
|
46
|
+
exact: true
|
|
47
|
+
}, options)
|
|
48
|
+
// --- Direct hook call.
|
|
49
|
+
useQueryClient().cancelQueries({
|
|
50
|
+
queryKey: [stringLiteralKey],
|
|
51
|
+
exact: true
|
|
52
|
+
}, options)
|
|
53
|
+
|
|
54
|
+
return <div>Example Component</div>
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const ExampleWithTemplateLiteral = () => {
|
|
58
|
+
useQuery({
|
|
59
|
+
queryKey: [`todos`],
|
|
60
|
+
exact: true
|
|
61
|
+
}, options)
|
|
62
|
+
useMutation({
|
|
63
|
+
mutationKey: [`todos`],
|
|
64
|
+
exact: true
|
|
65
|
+
}, options)
|
|
66
|
+
// QueryClient methods
|
|
67
|
+
// --- Instantiated hook call.
|
|
68
|
+
const queryClient = useQueryClient()
|
|
69
|
+
queryClient.cancelQueries({
|
|
70
|
+
queryKey: [`todos`],
|
|
71
|
+
exact: true
|
|
72
|
+
}, options)
|
|
73
|
+
// --- Direct hook call.
|
|
74
|
+
useQueryClient().cancelQueries({
|
|
75
|
+
queryKey: [`todos`],
|
|
76
|
+
exact: true
|
|
77
|
+
}, options)
|
|
78
|
+
|
|
79
|
+
return <div>Example Component</div>
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const ExampleWithTemplateLiteralIdentifier = () => {
|
|
83
|
+
const templateLiteralKey = `todos`
|
|
84
|
+
useQuery({
|
|
85
|
+
queryKey: [templateLiteralKey],
|
|
86
|
+
exact: true
|
|
87
|
+
}, options)
|
|
88
|
+
useMutation({
|
|
89
|
+
mutationKey: [templateLiteralKey],
|
|
90
|
+
exact: true
|
|
91
|
+
}, options)
|
|
92
|
+
// QueryClient methods
|
|
93
|
+
// --- Instantiated hook call.
|
|
94
|
+
const queryClient = useQueryClient()
|
|
95
|
+
queryClient.cancelQueries({
|
|
96
|
+
queryKey: [templateLiteralKey],
|
|
97
|
+
exact: true
|
|
98
|
+
}, options)
|
|
99
|
+
// --- Direct hook call.
|
|
100
|
+
useQueryClient().cancelQueries({
|
|
101
|
+
queryKey: [templateLiteralKey],
|
|
102
|
+
exact: true
|
|
103
|
+
}, options)
|
|
104
|
+
|
|
105
|
+
return <div>Example Component</div>
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export const ExampleWithArrayExpression = () => {
|
|
109
|
+
useQuery({ queryKey: ['todos'], exact: true }, options)
|
|
110
|
+
useMutation({ mutationKey: ['todos'], exact: true }, options)
|
|
111
|
+
// QueryClient methods
|
|
112
|
+
// --- Instantiated hook call.
|
|
113
|
+
const queryClient = useQueryClient()
|
|
114
|
+
queryClient.cancelQueries({ queryKey: ['todos'], exact: true }, options)
|
|
115
|
+
// --- Direct hook call.
|
|
116
|
+
useQueryClient().cancelQueries({ queryKey: ['todos'], exact: true }, options)
|
|
117
|
+
|
|
118
|
+
return <div>Example Component</div>
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export const ExampleWithArrayExpressionIdentifier = () => {
|
|
122
|
+
const arrayExpressionKey = ['todos']
|
|
123
|
+
useQuery({ queryKey: arrayExpressionKey, exact: true }, options)
|
|
124
|
+
useMutation({ mutationKey: arrayExpressionKey, exact: true }, options)
|
|
125
|
+
// QueryClient methods
|
|
126
|
+
// --- Instantiated hook call.
|
|
127
|
+
const queryClient = useQueryClient()
|
|
128
|
+
queryClient.cancelQueries({ queryKey: arrayExpressionKey, exact: true }, options)
|
|
129
|
+
// --- Direct hook call.
|
|
130
|
+
useQueryClient().cancelQueries({ queryKey: arrayExpressionKey, exact: true }, options)
|
|
131
|
+
|
|
132
|
+
return <div>Example Component</div>
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export const ExampleWithUnknownIdentifier1 = () => {
|
|
136
|
+
const createKey = (id) => ['todos', id]
|
|
137
|
+
const createdKey1 = createKey(1)
|
|
138
|
+
useQuery({ queryKey: createdKey1, exact: true }, options)
|
|
139
|
+
useMutation({ mutationKey: createdKey1, exact: true }, options)
|
|
140
|
+
// QueryClient methods
|
|
141
|
+
// --- Instantiated hook call.
|
|
142
|
+
const queryClient = useQueryClient()
|
|
143
|
+
queryClient.cancelQueries({ queryKey: createdKey1, exact: true }, options)
|
|
144
|
+
// --- Direct hook call.
|
|
145
|
+
useQueryClient().cancelQueries({ queryKey: createdKey1, exact: true }, options)
|
|
146
|
+
|
|
147
|
+
return <div>Example Component</div>
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export const ExampleWithUnknownIdentifier2 = () => {
|
|
151
|
+
const createdKey2 = createKey()
|
|
152
|
+
useQuery({ queryKey: createdKey2, exact: true }, options)
|
|
153
|
+
useMutation({ mutationKey: createdKey2, exact: true }, options)
|
|
154
|
+
// QueryClient methods
|
|
155
|
+
// --- Instantiated hook call.
|
|
156
|
+
const queryClient = useQueryClient()
|
|
157
|
+
queryClient.cancelQueries({ queryKey: createdKey2, exact: true }, options)
|
|
158
|
+
// --- Direct hook call.
|
|
159
|
+
useQueryClient().cancelQueries({ queryKey: createdKey2, exact: true }, options)
|
|
160
|
+
|
|
161
|
+
return <div>Example Component</div>
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export const ExampleWithUnknownIdentifier3 = () => {
|
|
165
|
+
useQuery({ queryKey: unknownQueryKey, exact: true }, options)
|
|
166
|
+
useMutation({ mutationKey: unknownQueryKey, exact: true }, options)
|
|
167
|
+
// QueryClient methods
|
|
168
|
+
// --- Instantiated hook call.
|
|
169
|
+
const queryClient = useQueryClient()
|
|
170
|
+
queryClient.cancelQueries({ queryKey: unknownQueryKey, exact: true }, options)
|
|
171
|
+
// --- Direct hook call.
|
|
172
|
+
useQueryClient().cancelQueries({ queryKey: unknownQueryKey, exact: true }, options)
|
|
173
|
+
|
|
174
|
+
return <div>Example Component</div>
|
|
175
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// React Query
|
|
2
|
+
import { useQuery, useQueryClient } from 'react-query'
|
|
3
|
+
import { useQuery as RenamedUseQuery, useQueryClient as RenamedUseQueryClient } from 'react-query'
|
|
4
|
+
import DefaultReactQuery from 'react-query'
|
|
5
|
+
import * as NamespacedReactQuery from 'react-query'
|
|
6
|
+
// Devtools
|
|
7
|
+
import { ReactQueryDevtools } from 'react-query/devtools'
|
|
8
|
+
import { ReactQueryDevtools as RenamedReactQueryDevtools } from 'react-query/devtools'
|
|
9
|
+
import DefaultReactQueryDevtools from 'react-query/devtools'
|
|
10
|
+
import * as NamespacedReactQueryDevtools from 'react-query/devtools'
|