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 :: check if string is empty 
Javascript :: js substr 
Javascript :: substring methods example 
Javascript :: or operator javascript 
Javascript :: JavaScript try...catch in setTimeout 
Javascript :: auto scroll to view react-native 
Javascript :: leaflet remove layergroup 
Javascript :: useref in functional component 
Javascript :: change image onclick javascript 
Javascript :: run jest test for a single file 
Javascript :: trigger keyboard event javascript 
Javascript :: get local year in js 
Javascript :: Encoding and Decoding Base64 Strings in Node.js 
Javascript :: datatable set row id 
Javascript :: how to make bootstrap navbar to change on scroll 
Javascript :: fetch data with axios in reactjs 
Javascript :: babel debugging 
Javascript :: buffer nodejs 
Javascript :: paragraph antd 
Javascript :: javascript convert utc to local time 
Javascript :: usestate wait for set 
Javascript :: get height webview from url video react native 
Javascript :: (error) = { console.log(error); } 
Javascript :: javascript slice method 
Javascript :: automatically click button javascript on setinterval 
Javascript :: multiple if statements js es6 inline 
Javascript :: Object.values returns 
Javascript :: javascript set max length of string 
Javascript :: validation in react native 
Javascript :: append raw html javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =