Skip to content

Commit adf0efe

Browse files
committed
chore: update apis for posts
1 parent 0fa015e commit adf0efe

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

src/api/posts/use-post.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ type Variables = { id: string };
88
type Response = Post;
99

1010
export 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
});

src/api/posts/use-posts.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ type Response = Post[];
88
type 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

1010
export 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
});

src/app/feed/[id].tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)