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 :: create random hex in node 
Javascript :: get current page name in javascript 
Javascript :: discord bot status javascript 
Javascript :: javascript get device gpu info 
Javascript :: get params in nuxtjs 
Javascript :: js pi 
Javascript :: js onclick open the phone application 
Javascript :: jquery click on parent but not child 
Javascript :: javascript password generator example 
Javascript :: scoll a div to bottom in angular 
Javascript :: get local storage javascript 
Javascript :: js proxy to array 
Javascript :: javascript loop through array backward 
Javascript :: next js get current url 
Javascript :: get input field inside div jquery 
Javascript :: how to set session storage in javascript 
Javascript :: Math.random javascript double 
Javascript :: react eslint error missing in props validation 
Javascript :: generate random numbers in js 
Javascript :: yeet 
Javascript :: Masonry js cdn 
Javascript :: get current page title javascript 
Javascript :: nodejs open default browser on specific web page 
Javascript :: sort js array by date 
Javascript :: upload files in react using axios 
Javascript :: valid email patter check jquery 
Javascript :: js get object by id from array 
Javascript :: int to string js 
Javascript :: javascript repeat element in array 
Javascript :: active link color different in react js 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =