Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

286
Views
How to reset setValues in react-hook-form version 7?

I have form some prefilled values from api and i set them with setValues('input-field-name','value-got-from-api') and when a i use reset method of react-hook-form it resets the newly added data but it does not reset the whole data in fields. For example. if a input fields value with setValue previously is 123 and if i typed 123abc it resets the abc part and sets the fields to 12345. But i wanted to reset to null or blank form.

The direct question will be , how can i reset the form fields either by using plain js or using react-hook-form ?

PS: i tried reset() method from rect-hook-form and plain js reset document.getElementById('myform').reset(); but noting works.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use the reset method returned from useForm hook.

export default function App() {
  const { register, handleSubmit, reset } = useForm();
  const onSubmit = (data, e) => {};

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <input {...register("firstName", { required: true })} />
      <input {...register("lastName")} />
      <input type="button" onClick={() => {
        reset({
          firstName: "default value",
        }, {
          keepErrors: true, 
          keepDirty: true,
          keepIsSubmitted: false,
          keepTouched: false,
          keepIsValid: false,
          keepSubmitCount: false,
        });
      }} />
    </form>
  );
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!