小编Wme*_*Man的帖子

异步函数作为 prop 传递到 React 组件中,导致 @typescript-eslint/no-misused-promises 错误

I have the following asynchronous submitNewPatient function which is throwing @typescript-eslint/no-misused-promises error message from elint. Is it possible to adjust the function such that it removes this error?

const submitNewPatient = async (values: PatientFormValues) => {
    try {
      const { data: newPatient } = await axios.post<Patient>(
        `${apiBaseUrl}/patients`,
        values
      );
      dispatch({ type: "ADD_PATIENT", payload: newPatient });
      closeModal();
    } catch (e: unknown) {
      if (axios.isAxiosError(e)) {
        console.error(e?.response?.data || "Unrecognized axios error");
        setError(
          String(e?.response?.data?.error) || "Unrecognized axios error"
        );
      } else {
        console.error("Unknown …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs asynchronous-javascript axios react-functional-component

4
推荐指数
1
解决办法
4396
查看次数