File tree Expand file tree Collapse file tree 3 files changed +6
-9
lines changed
Expand file tree Collapse file tree 3 files changed +6
-9
lines changed Original file line number Diff line number Diff line change @@ -8,10 +8,10 @@ type Variables = { id: string };
88type Response = Post ;
99
1010export const usePost = createQuery < Response , Variables , AxiosError > ( {
11- primaryKey : 'posts' ,
12- queryFn : ( { queryKey : [ primaryKey , variables ] } ) => {
11+ queryKey : [ 'posts' ] , // we recommend using endpoint base url as queryKey
12+ fetcher : ( variables ) => {
1313 return client
14- . get ( `${ primaryKey } /${ variables . id } ` )
14+ . get ( `posts /${ variables . id } ` )
1515 . then ( ( response ) => response . data ) ;
1616 } ,
1717} ) ;
Original file line number Diff line number Diff line change @@ -8,10 +8,8 @@ type Response = Post[];
88type Variables = void ; // as react-query-kit is strongly typed, we need to specify the type of the variables as void in case we don't need them
99
1010export const usePosts = createQuery < Response , Variables , AxiosError > ( {
11- primaryKey : 'posts' , // we recommend using endpoint base url as primaryKey
12- queryFn : ( { queryKey : [ primaryKey ] } ) => {
13- // in case if variables is needed, we can use destructuring to get it from queryKey array like this: ({ queryKey: [primaryKey, variables] })
14- // primaryKey is 'posts' in this case
15- return client . get ( `${ primaryKey } ` ) . then ( ( response ) => response . data . posts ) ;
11+ queryKey : [ 'posts' ] , // we recommend using endpoint base url as queryKey
12+ fetcher : ( ) => {
13+ return client . get ( `posts` ) . then ( ( response ) => response . data . posts ) ;
1614 } ,
1715} ) ;
Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ export default function Post() {
88 const local = useLocalSearchParams < { id : string } > ( ) ;
99
1010 const { data, isLoading, isError } = usePost ( {
11- //@ts -ignore
1211 variables : { id : local . id } ,
1312 } ) ;
1413
You can’t perform that action at this time.
0 commit comments