Answers for "reset a form in react"

0

clear form in react

//with the useref hook you can do it easily
const form = useRef(null);

const handlesubmit = () => {
  form.current.reset(); //this will reset all the inputs in the form
}
<form ref={form} onSubmit={handlesubmit}></form>
Posted by: Guest on October-15-2021
1

reset form in react

<!-- you just need a button type of reset -->
<form>
  <div>
   <label for="name">Name</label>
   <input type="text" id="name" placeholder="name" />
  </div>
  <div>
   <label for="password">Password</label>
   <input type="password" id="password" placeholder="password" />
  </div>
  <button type="reset">Reset</button> 
  <button>Submit</button>
</form>
Posted by: Guest on June-12-2021

Browse Popular Code Answers by Language