React-Query useMutation

김정현·2023년 2월 21일
0

React

목록 보기
9/10

1. Axois post

export const AxiosPost = async (보내는 값) => {
  try {
    const res = await axios.post(URL,보내는 값);

    return res;
  } catch (err) {
  console.error(err)
  }
};

2. React-Query

const { mutate, isLoading } = useMutation(AxiosPost, {
    onError: (err) => alert("신청서 등록에 실패하였습니다."),
    onSuccess: () => {
      navigate("/page");
    },
  });

3. Button Event(ex)

const FE = (e: React.MouseEvent<HTMLButtonElement>) => {
    mutate({
  		id: id,
  		password: password
    });
 };
profile
개발일지

0개의 댓글