In my app I have a login form where user can type his email and then get an email link. I wonder should I use useMutation (not much experienced with its use cases) for onSubmit to avoid adding states for loading, error, etc.
LoginFrom:
export const LoginForm = () => {
const [loading, setLoading] = useState(false);
const [error, setError] = useState("");
const [info, setInfo] = useState("");
const onSubmit = (data: Inputs) => {
setLoading(true);
sendSignInLinkToEmail(auth, data.email, {
url: "http://localhost:5173/landing",
handleCodeInApp: true,
})
.then(() => {
localStorage.setItem("email", data.email);
setLoading(false);
setError("");
setInfo("Email link has been sent");
})
.catch((error) => {
setLoading(false);
setError(error.message);
});
};
return (
<CommonForm
onSubmit={onSubmit}
buttonText="Send Email Link"
isPending={loading}
isError={error}
infoMessage={info}
/>
);
};