File size: 1,435 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import * as React from 'react'
import { useMutation, useQuery, useQueryClient } from 'react-query'
export const ExampleWithStringLiteralKey = () => {
const stringLiteralKey = 'todos'
useQuery(stringLiteralKey)
useMutation(stringLiteralKey)
// QueryClient methods
// --- Instantiated hook call.
const queryClient = useQueryClient()
queryClient.cancelQueries(stringLiteralKey)
// --- Direct hook call.
useQueryClient().cancelQueries(stringLiteralKey)
return <div>Example Component</div>
}
export const ExampleWithTemplateLiteral = () => {
const templateLiteralKey = `todos`
useQuery(templateLiteralKey)
useMutation(templateLiteralKey)
}
export const ExampleWithArrayExpressionKey = () => {
const arrayExpressionKey = ['todos']
useQuery(arrayExpressionKey)
useMutation(arrayExpressionKey)
// QueryClient methods
// --- Instantiated hook call.
const queryClient = useQueryClient()
queryClient.cancelQueries(queryKey2)
// --- Direct hook call.
useQueryClient().cancelQueries(queryKey2)
return <div>Example Component</div>
}
export const ExampleWithUnknownKey = () => {
useQuery(unknownQueryKey)
useMutation(unknownQueryKey)
// QueryClient methods
// --- Instantiated hook call.
const queryClient = useQueryClient()
queryClient.cancelQueries(unknownQueryKey)
// --- Direct hook call.
useQueryClient().cancelQueries(unknownQueryKey)
return <div>Example Component</div>
}
|