Open History to see the last commit
1import * as React from 'react'
2import { useQuery } from '@tanstack/react-query'
3β
4export const WithObjectPattern = () => {
5 const { isError, isLoading, isSuccess, status } = useQuery({
6 queryKey: ['queryKey'],
7 queryFn: () => ['data'],
8 })
9β
10 if (isError || isLoading || isSuccess) {
11 console.log('Do something')
12 }
13β
14 return <div>{JSON.stringify({ isError, isLoading, isSuccess, status })}</div>
15}
16β
17export const WithObjectPatternAndRename = () => {
18 const { isError, isLoading: isLoadingRenamed, isSuccess, status } = useQuery({
19 queryKey: ['queryKey'],
20 queryFn: () => ['data'],
21 })
22β
23 if (isError || isLoadingRenamed || isSuccess) {
24 console.log('Do something')
25 }
26β
27 return <div>{JSON.stringify({ isError, isLoadingRenamed, isSuccess, status })}</div>
28}
29β
30export const WithObjectPatternAndRestElement = () => {
31 const { isError, ...rest } = useQuery({
32 queryKey: ['queryKey'],
33 queryFn: () => ['data'],
34 })
35β
36 if (isError || rest.isLoading || rest.isSuccess) {
37 console.log('Do something')
38 }
39β
40 return <div>{JSON.stringify({ isError, isLoading: rest.isLoading, isSuccess: rest.isSuccess })}</div>
41}
42β
43export const WithIdentifier = () => {
44 const queryResult = useQuery({
45 queryKey: ['queryKey'],
46 queryFn: () => ['data'],
47 })
48β
49 if (queryResult.isError || queryResult.isLoading || queryResult.isSuccess) {
50 console.log('Do something')
51 }
52β
53 return <div>{JSON.stringify(queryResult)}</div>
54}
55β
56export const WithCombinations = () => {
57 function useSomethingElse() {
58 const { isError, isLoading, isSuccess, status } = useQuery({
59 queryKey: ['somethingElse'],
60 queryFn: () => ['data'],
61 })
62β
63 return { isError, isLoading, isSuccess, status }
64 }
65β
66 function useAnotherThing() {
67 const { isLoading, ...rest } = useQuery({
68 queryKey: ['anotherThing'],
69 queryFn: () => ['anotherData'],
70 })
71β
72 return { isLoading: rest.isLoading, ...rest }
73 }
74β
75 const { isError, isLoading: isLoadingRenamed, isSuccess, status } = useQuery({
76 queryKey: ['queryKey'],
77 queryFn: () => ['data'],
78 })
79β
80 return isLoadingRenamed
81}