Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

npm react hook form

npm i react-hook-form
Comment

react form hook npm

yarn add react-hook-form
Comment

npm hook form

import React from 'react';import { useForm } from 'react-hook-form'; function App() {  const { register, handleSubmit, errors } = useForm(); // initialise the hook  const onSubmit = (data) => {    console.log(data);  };   return (    <form onSubmit={handleSubmit(onSubmit)}>      <input name="firstname" ref={register} /> {/* register an input */}            <input name="lastname" ref={register({ required: true })} />      {errors.lastname && 'Last name is required.'}            <input name="age" ref={register({ pattern: /d+/ })} />      {errors.age && 'Please enter number for age.'}            <input type="submit" />    </form>  );}
Comment

react-hook-form-input npm

$ npm install react-hook-form-input
Comment

react-hook-form-input npm

import React from 'react';import useForm from 'react-hook-form';import { RHFInput } from 'react-hook-form-input';import Select from 'react-select'; const options = [  { value: 'chocolate', label: 'Chocolate' },  { value: 'strawberry', label: 'Strawberry' },]; function App() {  const { handleSubmit, register, setValue, reset } = useForm();   return (    <form onSubmit={handleSubmit(data => console.log(data))}>      <RHFInput        as={<Select options={options} />}        rules={{ required: true }}        name="reactSelect"        register={register}        setValue={setValue}      />      <button type="button">        Reset Form      </button>      <button>submit</button>    </form>  );}
Comment

PREVIOUS NEXT
Code Example
Javascript :: nestjs 
Javascript :: javascript break and continue 
Javascript :: timestamp to unix time react 
Javascript :: How to fetch data from an api async and await 
Javascript :: react hook form reset only one field 
Javascript :: js or 
Javascript :: mongoose check if user exists 
Javascript :: js find in array 
Javascript :: what is undefined 
Javascript :: map keys to list node js 
Javascript :: jest spyon 
Javascript :: electron js execute command 
Javascript :: js library for unique id uniqid 
Javascript :: angular server start command 
Javascript :: jQ - on image load 
Javascript :: Uncaught TypeError: document.getContext is not a function 
Javascript :: react laravel 
Javascript :: longitud objeto javascript 
Javascript :: flatten json python 
Javascript :: array any 
Javascript :: javascript get next dom element 
Javascript :: datatable change classname by value 
Javascript :: resize canvas javascript 
Javascript :: regex not js 
Javascript :: jwt strategy 
Javascript :: add onclick javascript dynamically 
Javascript :: using python with javascript 
Javascript :: react particles 
Javascript :: variable javascript 
Javascript :: javascript first letter uppercase 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =