import { useQuery } from "@tanstack/react-query";
import { getLanguage } from "taehui-ts/language";

import { wwwAXIOS } from "src/Www";
import { GetLatestEssayAPI } from "src/wwwAPI";

export default function useGetLatestEssay() {
  const language = getLanguage();
  return useQuery({
    queryKey: ["latestEssay"],
    queryFn: async () => {
      const { data } = await wwwAXIOS.get<GetLatestEssayAPI>("/essay/latest", {
        params: { language },
      });
      return data;
    },
    initialData: [],
  });
}
