Download react-hook-form/examples/V7/validationOnFieldChange.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.24 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-hook-form/examples/V7/validationOnFieldChange.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-hook-form/examples/V7/validationOnFieldChange.tsx
-
curl -L -o validationOnFieldChange.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-hook-form/examples/V7/validationOnFieldChange.tsx
1.24 kB
| import React from 'react'; | |
| import ReactDOM from 'react-dom'; | |
| import { useForm } from 'react-hook-form'; | |
| export default function App() { | |
| const { | |
| register, | |
| formState: { errors }, | |
| handleSubmit, | |
| } = useForm({ | |
| mode: 'onChange', | |
| }); | |
| const onSubmit = (data) => { | |
| alert(JSON.stringify(data)); | |
| }; | |
| return ( | |
| <div className="App"> | |
| <form onSubmit={handleSubmit(onSubmit)}> | |
| <div> | |
| <label htmlFor="firstName">First Name</label> | |
| <input | |
| placeholder="bill" | |
| {...register('firstName', { required: true })} | |
| /> | |
| {errors.firstName && 'This is required'} | |
| </div> | |
| <div> | |
| <label htmlFor="lastName">Last Name</label> | |
| <input | |
| placeholder="luo" | |
| {...register('lastName', { required: true })} | |
| /> | |
| {errors.lastName && 'This is required'} | |
| </div> | |
| <div> | |
| <label htmlFor="email" placeholder="bluebill1049@hotmail.com"> | |
| </label> | |
| <input {...register('email', { required: true })} /> | |
| {errors.email && 'This is required'} | |
| </div> | |
| <button type="submit">Submit</button> | |
| </form> | |
| </div> | |
| ); | |
| } | |