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

default-import.output.tsx

82 lines2.1 KB

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