admin管理员组文章数量:1122832
I'm using react-hook-form
to create a login/signup form; however, when I use onSubmit={handleSubmit(onSubmit}}
or onClick={handleGoogleSignIn}
I'm receiving the following error:
Promise-returning function provided to attribute where a void return was expected.eslint@typescript-eslint/no-misused-promises const handleGoogleSignIn: () => Promise
Below is the relevant code:
import { useForm, SubmitHandler } from "react-hook-form";
import Swal from "sweetalert2";
const SignUp = () => {
// Removed for brevity
...
// imports for react-hook-form
const {
register,
handleSubmit,
reset,
formState: { errors },
} = useForm<FormInput>();
// sign up function
const onSubmit: SubmitHandler<FormInput> = async (data) => {
// check if user is already logged in
if (user) {
await Swal.fire({
icon: "error",
title: "Already Logged in",
}).then((result) => {
if (result.isConfirmed) {
navigate(from, { replace: true });
}
});
reset();
}
// get the information from the user
const name = data.name;
const email = data.email;
const phoneNumber = data.phoneNumber;
const password = data.password;
const userInfo: UserInfo = { name, email, phoneNumber, password };
// Create new user
await createUser?.(email, password)
.then((result) => {
if (result.user) {
// update user name after account creation
updateUserName?.(name)
.then(() => {
void Swal.fire({
icon: "success",
title: "Account Created",
showConfirmButton: false,
timer: 1500,
});
setTimeout(() => {
navigate(from, { replace: true });
}, 1600);
})
.catch((error) => {
console.log(error);
});
}
})
.catch((error) => {
console.log(error);
});
reset();
};
return (
<div>
<form onSubmit={handleSubmit(onSubmit)}>
...
</form>
</div>
);
};
export default SignUp;
I've tried using an arrow function inside of the callback, like onSubmit={() => { handleSubmit(onSubmit)}}
but that also doesn't work. Additionally, I've tried onSubmit={(e) => { handleSubmit(onSubmit) }}
but it also doesn't work, passing the e
param gives another error because react-hook-form
already has a default data
as its parameter.
本文标签: javascriptReact hook form promise function error in TypescriptreactjsStack Overflow
版权声明:本文标题:javascript - React hook form promise function error in Typescript-reactjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736301720a1931274.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论