Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

clear input field react-hook-form

const InputForm = () => {
  const { register, handleSubmit, reset } = useForm();

  const onSubmit = (data) => {
    //...
    reset();
  };
Comment

react hook form reset

// destructure reset from useForm as like below
const { register, handleSubmit, errors, reset } = useForm();
// then call the reset function when all of the data has been sent to the server
reset();

//example:
  const { register, handleSubmit, errors, reset } = useForm();
  const onSubmit = (data) => {
    const url = 'http://localhost:5000/item';
    axios
      .post(url, {
        ...data,
      })
      .then((res) => {
        if (res.data.acknowledged) {
          toast('Item Added Successfully...');
          reset(); // here I am reseting the form
        }
      });
  };
Comment

react hook form reset only one field

resetField('input-name'); // register input and resetField works
Comment

react hook form clear form

// ❌ avoid the following with deep nested default values
const defaultValues = { object: { deepNest: { file: new File() } } };
useForm({ defaultValues });
reset(defaultValues); // share the same reference

// ✅ it's safer with the following, as we only doing shallow clone with defaultValues
useForm({ deepNest: { file: new File() } });
reset({ deepNest: { file: new File() } });
Comment

PREVIOUS NEXT
Code Example
Javascript :: react native tab navigation header 
Javascript :: javascript unicode to string 
Javascript :: kotlin jsonobject to class 
Javascript :: how to send the mail using node with template 
Javascript :: multiple conditions for JavaScript .includes() method 
Javascript :: proxy nuxt 
Javascript :: what is undefined 
Javascript :: como eliminar un elemento del dom con javascript 
Javascript :: angular img tag 
Javascript :: add val in data-id jquery 
Javascript :: javascript string.includes 
Javascript :: nodemon install locally json file 
Javascript :: Vue 3 script setup props emits 
Javascript :: mongodb aggregate project 
Javascript :: dummy data json 
Javascript :: js max array 
Javascript :: var js 
Javascript :: function is not defined in jquery 
Javascript :: canvas drawimage resize quality 
Javascript :: javascript last in a list 
Javascript :: javascript check if array is empty or null or undefined 
Javascript :: conditional onclick react 
Javascript :: null value check in react js 
Javascript :: javascript remove required attribute 
Javascript :: mongodb text search exact match 
Javascript :: change all a tag href javascript 
Javascript :: chess game in javascript github 
Javascript :: angular countdown begin stop pause 
Javascript :: smtp js 
Javascript :: is palindrome 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =