Skip to content

How to reset form after submit in React Hook Form? #12991

Closed Answered by AmanRai8
PriyankaChaudhary0075 asked this question in Q&A
Discussion options

You must be logged in to vote

You can use the reset() function from React Hook Form to reset the form after submission.

Example:

const { register, handleSubmit, reset } = useForm({
  defaultValues: {
    name: "",
    email: "",
  },
});

const onSubmit = (data) => {
  console.log(data);
  reset(); // resets to default values
};

If you want to reset with new values, you can do:
reset({ name: "John", email: "" });

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by PriyankaChaudhary0075
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants