0

// 我如何使用 toastify 的承诺,就像我想在获取数据时显示微调器然后消息成功或失败

// 但我在下面的代码中遇到错误

const fetch = () => { axios

  .get("https://restcountries.com/v2/name/india")
  .then((res) => {
    toast.promise({
      pending:"pending",
      success:"success",
      error:"rejected"
    } )
    console.log(res);
  })
  .catch((err) => {
    toast.error(" failed", {
      position: "top-center",
      autoClose: 2000,
      hideProgressBar: true,
      closeOnClick: true,
      pauseOnHover: true,
      draggable: true,
      progress: undefined
    });
  });

};

4

1 回答 1

0

根据 toast API,语法应该是

const myPromise = fetchData();


toast.promise(myPromise, {
   loading: 'Loading',
   success: 'Got the data',
   error: 'Error when fetching',
})

您在他们的文档上阅读了更多内容https://react-hot-toast.com/docs/toast

于 2022-03-03T18:57:11.987 回答