/
githubmirror
/
react-hook-form
Обзор
Документация
Войти
/
githubmirror
/
react-hook-form
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/V6/nativeMultipleInput.tsx
38 строк
1006 B
Bill
7️⃣ V7 (#3741)
01 апр 2021, 00:14
Не верифицирован
01 апр 2021, 00:14
9555d16
Код
Авторство
О чём код?
import React from 'react'; import { useForm, NestedValue } from 'react-hook-form'; export default function App() { const { register, errors, handleSubmit } = useForm<{ email: NestedValue<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> ); }