react-query, Type ‘string[]’ has no properties in common with type ‘InvalidateQueryFilters’

luna·2024년 9월 9일

프로젝트에서 react-query 를 사용하려고 하는데 다음과 같은 에러가 났다.

뭐여... 하고 알아보니 query key 를 넣는 옵션이 아래와 같이 바뀌었던 것

queryClient.invalidateQueries({ queryKey: ['todos'] })

해당 부분만 바꿔주니 잘 되었다.

// 방명록 생성
export const useCreateGuestBook = () => {
  const queryClient = useQueryClient();
  return useMutation({
    mutationKey: ["createGuestbook"],
    mutationFn: async (newEntry: guestbookType) => {
      const docRef = await addDoc(collection(db, "guestbook"), newEntry);
      return { id: docRef.id, ...newEntry };
    },
    onSuccess: () => {
      queryClient.invalidateQueries({
        queryKey: ["guestbooklist"],
      });
    },
  });
};

참고

0개의 댓글