11/* eslint-disable jsx-a11y/anchor-is-valid */
2- import React from 'react'
3- import ReactDOM from 'react-dom/client'
2+ import React from 'react' ;
3+ import ReactDOM from 'react-dom/client' ;
44import {
55 useQuery ,
66 useQueryClient ,
77 QueryClient ,
88 QueryClientProvider ,
9- } from '@tanstack/react-query'
10- import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
11- import { request , gql } from 'graphql-request'
9+ } from '@tanstack/react-query' ;
10+ import { ReactQueryDevtools } from '@tanstack/react-query-devtools' ;
11+ import { request , gql } from 'graphql-request' ;
1212
13- const endpoint = 'https://graphqlzero.almansi.me/api'
13+ const endpoint = 'https://graphqlzero.almansi.me/api' ;
1414
15- const queryClient = new QueryClient ( )
15+ const queryClient = new QueryClient ( ) ;
1616
1717function App ( ) {
18- const [ postId , setPostId ] = React . useState ( - 1 )
18+ const [ postId , setPostId ] = React . useState ( - 1 ) ;
1919
2020 return (
2121 < QueryClientProvider client = { queryClient } >
@@ -36,7 +36,7 @@ function App() {
3636 ) }
3737 < ReactQueryDevtools initialIsOpen />
3838 </ QueryClientProvider >
39- )
39+ ) ;
4040}
4141
4242function usePosts ( ) {
@@ -56,16 +56,16 @@ function usePosts() {
5656 }
5757 }
5858 }
59- ` ,
60- )
61- return data
59+ `
60+ ) ;
61+ return data ;
6262 } ,
63- } )
63+ } ) ;
6464}
6565
6666function Posts ( { setPostId } ) {
67- const queryClient = useQueryClient ( )
68- const { status, data, error, isFetching } = usePosts ( )
67+ const queryClient = useQueryClient ( ) ;
68+ const { status, data, error, isFetching } = usePosts ( ) ;
6969
7070 return (
7171 < div >
@@ -104,13 +104,13 @@ function Posts({ setPostId }) {
104104 ) }
105105 </ div >
106106 </ div >
107- )
107+ ) ;
108108}
109109
110110function usePost ( postId ) {
111- return useQuery (
112- [ 'post' , postId ] ,
113- async ( ) => {
111+ return useQuery ( {
112+ queryKey : [ 'post' , postId ] ,
113+ queryFn : async ( ) => {
114114 const { post } = await request (
115115 endpoint ,
116116 gql `
@@ -121,19 +121,16 @@ function usePost(postId) {
121121 body
122122 }
123123 }
124- ` ,
125- )
126-
127- return post
128- } ,
129- {
130- enabled : ! ! postId ,
124+ `
125+ ) ;
126+ return post ;
131127 } ,
132- )
128+ enabled : postId > - 1 ,
129+ } ) ;
133130}
134131
135132function Post ( { postId, setPostId } ) {
136- const { status, data, error, isFetching } = usePost ( postId )
133+ const { status, data, error, isFetching } = usePost ( postId ) ;
137134
138135 return (
139136 < div >
@@ -156,8 +153,8 @@ function Post({ postId, setPostId }) {
156153 </ >
157154 ) }
158155 </ div >
159- )
156+ ) ;
160157}
161158
162- const rootElement = document . getElementById ( 'root' )
163- ReactDOM . createRoot ( rootElement ) . render ( < App /> )
159+ const rootElement = document . getElementById ( 'root' ) ;
160+ ReactDOM . createRoot ( rootElement ) . render ( < App /> ) ;
0 commit comments