22 lines
603 B
TypeScript
22 lines
603 B
TypeScript
import { productApi } from "@/api/product-api.service";
|
|
import { delay } from "@/features/app";
|
|
import { type IPost } from "@/lib/utils";
|
|
import { useQuery } from "@tanstack/react-query";
|
|
|
|
const usePost = (post?: IPost) => {
|
|
const { isLoading, refetch, ...query } = useQuery({
|
|
queryKey: ["product", post?.id],
|
|
queryFn: async () => {
|
|
if (!post) return null;
|
|
|
|
await delay(300); // Giả lập delay để thấy loading
|
|
const res = await productApi.apiRequest("get", post);
|
|
return res;
|
|
},
|
|
});
|
|
|
|
return { isLoading, refetch, ...query };
|
|
};
|
|
|
|
export default usePost;
|