import useSWR , { SWRConfiguration } from "swr" ; import { PostQuery , PostRes } from "@/pages/api/post/[id]" ; import { fetcher } from "@/utils/fetcher" ; export interface UsePostProps extends SWRConfiguration , Partial < PostQuery > { } export const usePost = ( { id , ... config } ) => { const swr = useSWR < PostRes > ( ! id ? null : "/api/post/" + id , fetcher , config ) ; const isLoading = ! swr . error && ! swr . data ; return { ... swr , isLoading , } ; } ;