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 :: The slice JavaScript string method 
Javascript :: JavaScript throw with try...catch 
Javascript :: angular subscribe on value change 
Javascript :: angular decorators list 
Javascript :: [Homepage] is not a <Route component. All component children of <Routes must be a <Route or <React.Fragment 
Javascript :: javascript parseint 
Javascript :: javascript alert variable 
Javascript :: decimal to base 32 javascript 
Javascript :: react onchange multiple functions 
Javascript :: how to get csrf token in javascript 
Javascript :: add color to attribute using jquery 
Javascript :: javascript date validation less than today 
Javascript :: check if element with class has another class javascript 
Javascript :: $.get jquery return value 
Javascript :: react-slick 
Javascript :: includes() js 
Javascript :: math captcha 
Javascript :: manage nodejs versions on windows 
Javascript :: get text in protractor 
Javascript :: math.floor 
Javascript :: convert a string array into object using kerys 
Javascript :: nginx reverse proxy redirect 
Javascript :: js outputting data 
Javascript :: javascript split 
Javascript :: Initialize Axios React Redux CRUD API calls 
Javascript :: jquery slider move event 
Javascript :: ng select2 angular dropdown 
Javascript :: how to get value inside span using javascript 
Javascript :: how to handle errors with xmlhttprequest 
Javascript :: animate change background color angular 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =