Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

parameter-is-identifier.input.tsx

49 lines1.4 KB

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>
17​
18export const ExampleWithTemplateLiteral = () => {
19 const templateLiteralKey = `todos`
20 useQuery(templateLiteralKey)
21 useMutation(templateLiteralKey)
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>
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>