Newer
Older
taehui / qwilight-fe / src / app / [language] / note / query / useGetComment.ts
@Taehui Taehui on 25 Mar 765 bytes v1.0.0
import { GetCommentAPI } from "@/type/wwwAPI";
import { wwwAPI } from "@/utilities/wwwAPI";
import { useQuery } from "@tanstack/react-query";
import { useLanguage } from "taehui-ts/language";

export default function useGetComment(
  noteID: string,
  isCommentOpened: boolean,
  avatarID?: string,
) {
  const language = useLanguage();

  return useQuery({
    enabled: isCommentOpened,
    queryKey: ["comment", noteID, avatarID, language],
    queryFn: async () => {
      const { data } = await wwwAPI.get<GetCommentAPI>("/comment", {
        params: {
          noteID,
          avatarID,
          language,
        },
      });

      return data;
    },
    initialData: {
      comments: [],
      commentPlace: -1,
      totalComments: 0,
    },
  });
}