Open History to see the last commit
1import * as React from 'react'
2import { useMutation, useQuery, useQueryClient } from 'react-query'
3β
4const options = {}
5β
6export 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β
19export 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β
33export 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β
46export 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β
60export 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β
73export 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β
87export 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β
102export 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β
116export 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β