Download react-hook-form/examples/V7/nativeMultipleInput.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/examples/V7/nativeMultipleInput.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/examples/V7/nativeMultipleInput.tsx
-
curl -L -o nativeMultipleInput.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/examples/V7/nativeMultipleInput.tsx
1.01 kB
| import React from 'react'; | |
| import { useForm } from 'react-hook-form'; | |
| export default function App() { | |
| const { | |
| register, | |
| formState: { errors }, | |
| handleSubmit, | |
| } = useForm<{ | |
| email: string[]; | |
| }>({ | |
| defaultValues: { | |
| email: ['first@react.hook.form', 'last@react.hook.form'], | |
| }, | |
| }); | |
| const onSubmit = handleSubmit<{ email: string }>((data) => { | |
| alert(JSON.stringify(data)); | |
| }); | |
| return ( | |
| <form onSubmit={onSubmit}> | |
| <label>Native Multiple Input</label> | |
| <input | |
| multiple | |
| type="email" | |
| name="email" | |
| list="email" | |
| ref={register({ required: 'This is required.' })} | |
| /> | |
| <datalist id="email"> | |
| <option value="first@react.hook.form" /> | |
| <option value="second@react.hook.form" /> | |
| <option value="third@react.hook.form" /> | |
| <option value="last@react.hook.form" /> | |
| </datalist> | |
| {errors?.email && <p>{errors.email.message}</p>} | |
| <input type="submit" /> | |
| </form> | |
| ); | |
| } | |