react-query사용할 때 함수에서 isSuccess 쓰기

브리·2023년 6월 28일
0

버튼 클릭 함수를 눌렀을 때 서로 관계가 없는 두 개의 mutate를 호출한 뒤, 호출 결과가 isSuccess 일 때 특정 액션을 주고싶었음.
try catch + async await 주면 간단했음.

 const handleClickSubmit = async () => {
    try {
      await apiFn1.mutate({
        id,
        password,
      });

      await apiFn2.mutate({
        ~~~~,
        ~~~~,
        ~~~
      });

      if (apiFn1.isSuccess && apiFn2.isSuccess) {
        push(routerPaths.~~);
      }
    } catch (error) {
      console.log(error);
    }
  };
profile
무럭무럭

0개의 댓글