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

usePost.js

13 lines324 Bytes

1import { useQuery } from "react-query";
2import axios from "axios";
3​
4const getPostById = async (_, postId) => {
5 const { data } = await axios.get(
6 `https://jsonplaceholder.typicode.com/posts/${postId}`
7 );
8 return data;
9};
10​
11export default function usePost(postId) {
12 return useQuery(["post", postId], getPostById);