Weird behaviour of trigger
in useEffect
#7258
-
CodeSandbox: https://codesandbox.io/s/condescending-grothendieck-pzpqq?file=/src/App.js So in the above code sandbox there are two |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
I think the problem is due to calling related example: import React from "react";
import { useForm, useFieldArray, Controller } from "./src";
function App() {
const {
register,
handleSubmit,
reset,
formState: { isSubmitSuccessful }
} = useForm({ defaultValues: { something: "anything" } });
const onSubmit = (data) => {
console.log(data);
};
React.useEffect(() => {
if (formState.isSubmitSuccessful) {
reset({ something: '' });
}
}, [formState, submittedData, reset]);
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register("something")} />
<input type="submit" />
</form>
);
} |
Beta Was this translation helpful? Give feedback.
-
So I found which line actually fixes the issue - https://github.com/react-hook-form/react-hook-form/pull/6201/files#diff-5a85c1643c71f45e050ce584d7c0db2bdf2e56f8a7dae86d74fedf01be2d2cabR1088. I am still not really sure why |
Beta Was this translation helpful? Give feedback.
I think the problem is due to calling
reset
andtrigger
at the same time.related example: