Open History to see the last commit
1import * as React from 'react'
2import { useMutation, useQuery, useQueryClient } from 'react-query'
3β
4export 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β
18export const ExampleWithTemplateLiteral = () => {
19 const templateLiteralKey = `todos`
20 useQuery(templateLiteralKey)
21 useMutation(templateLiteralKey)
22}
23β
24export 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β
38export 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}