11/* eslint-disable jsx-a11y/anchor-is-valid */
2- import React from " react" ;
3- import ReactDOM from " react-dom/client" ;
4- import axios from " axios" ;
2+ import React from ' react'
3+ import ReactDOM from ' react-dom/client'
4+ import axios from ' axios'
55import {
66 useQuery ,
77 useQueryClient ,
88 QueryClient ,
99 QueryClientProvider ,
10- } from " @tanstack/react-query" ;
11- import { ReactQueryDevtools } from " @tanstack/react-query-devtools" ;
10+ } from ' @tanstack/react-query'
11+ import { ReactQueryDevtools } from ' @tanstack/react-query-devtools'
1212
13- const queryClient = new QueryClient ( ) ;
13+ const queryClient = new QueryClient ( )
1414
1515function App ( ) {
16- const [ postId , setPostId ] = React . useState ( - 1 ) ;
16+ const [ postId , setPostId ] = React . useState ( - 1 )
1717
1818 return (
1919 < QueryClientProvider client = { queryClient } >
2020 < p >
2121 As you visit the posts below, you will notice them in a loading state
2222 the first time you load them. However, after you return to this list and
2323 click on any posts you have already visited again, you will see them
24- load instantly and background refresh right before your eyes!{ " " }
24+ load instantly and background refresh right before your eyes!{ ' ' }
2525 < strong >
2626 (You may need to throttle your network speed to simulate longer
2727 loading sequences)
@@ -34,32 +34,32 @@ function App() {
3434 ) }
3535 < ReactQueryDevtools initialIsOpen />
3636 </ QueryClientProvider >
37- ) ;
37+ )
3838}
3939
4040function usePosts ( ) {
4141 return useQuery ( {
42- queryKey : [ " posts" ] ,
42+ queryKey : [ ' posts' ] ,
4343 queryFn : async ( ) => {
4444 const { data } = await axios . get (
45- " https://jsonplaceholder.typicode.com/posts"
46- ) ;
47- return data ;
45+ ' https://jsonplaceholder.typicode.com/posts' ,
46+ )
47+ return data
4848 } ,
49- } ) ;
49+ } )
5050}
5151
5252function Posts ( { setPostId } ) {
53- const queryClient = useQueryClient ( ) ;
54- const { status, data, error, isFetching } = usePosts ( ) ;
53+ const queryClient = useQueryClient ( )
54+ const { status, data, error, isFetching } = usePosts ( )
5555
5656 return (
5757 < div >
5858 < h1 > Posts</ h1 >
5959 < div >
60- { status === " pending" ? (
61- " Loading..."
62- ) : status === " error" ? (
60+ { status === ' pending' ? (
61+ ' Loading...'
62+ ) : status === ' error' ? (
6363 < span > Error: { error . message } </ span >
6464 ) : (
6565 < >
@@ -72,10 +72,10 @@ function Posts({ setPostId }) {
7272 style = {
7373 // We can access the query data here to show bold links for
7474 // ones that are cached
75- queryClient . getQueryData ( [ " post" , post . id ] )
75+ queryClient . getQueryData ( [ ' post' , post . id ] )
7676 ? {
77- fontWeight : " bold" ,
78- color : " green" ,
77+ fontWeight : ' bold' ,
78+ color : ' green' ,
7979 }
8080 : { }
8181 }
@@ -85,31 +85,31 @@ function Posts({ setPostId }) {
8585 </ p >
8686 ) ) }
8787 </ div >
88- < div > { isFetching ? " Background Updating..." : " " } </ div >
88+ < div > { isFetching ? ' Background Updating...' : ' ' } </ div >
8989 </ >
9090 ) }
9191 </ div >
9292 </ div >
93- ) ;
93+ )
9494}
9595
9696const getPostById = async ( id ) => {
9797 const { data } = await axios . get (
98- `https://jsonplaceholder.typicode.com/posts/${ id } `
99- ) ;
100- return data ;
101- } ;
98+ `https://jsonplaceholder.typicode.com/posts/${ id } ` ,
99+ )
100+ return data
101+ }
102102
103103function usePost ( postId ) {
104104 return useQuery ( {
105- queryKey : [ " post" , postId ] ,
105+ queryKey : [ ' post' , postId ] ,
106106 queryFn : ( ) => getPostById ( postId ) ,
107107 enabled : ! ! postId ,
108- } ) ;
108+ } )
109109}
110110
111111function Post ( { postId, setPostId } ) {
112- const { status, data, error, isFetching } = usePost ( postId ) ;
112+ const { status, data, error, isFetching } = usePost ( postId )
113113
114114 return (
115115 < div >
@@ -118,22 +118,22 @@ function Post({ postId, setPostId }) {
118118 Back
119119 </ a >
120120 </ div >
121- { ! postId || status === " pending" ? (
122- " Loading..."
123- ) : status === " error" ? (
121+ { ! postId || status === ' pending' ? (
122+ ' Loading...'
123+ ) : status === ' error' ? (
124124 < span > Error: { error . message } </ span >
125125 ) : (
126126 < >
127127 < h1 > { data . title } </ h1 >
128128 < div >
129129 < p > { data . body } </ p >
130130 </ div >
131- < div > { isFetching ? " Background Updating..." : " " } </ div >
131+ < div > { isFetching ? ' Background Updating...' : ' ' } </ div >
132132 </ >
133133 ) }
134134 </ div >
135- ) ;
135+ )
136136}
137137
138- const rootElement = document . getElementById ( " root" ) ;
139- ReactDOM . createRoot ( rootElement ) . render ( < App /> ) ;
138+ const rootElement = document . getElementById ( ' root' )
139+ ReactDOM . createRoot ( rootElement ) . render ( < App /> )
0 commit comments