/
githubmirror
/
react-hook-form
Обзор
Документация
Войти
/
githubmirror
/
react-hook-form
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/V7/formProvider.tsx
24 строки
666 B
Bill
⚙️ migrate from Select.options to Select.selectedOptions (#6678) (#6687)
01 окт 2021, 09:13
Не верифицирован
01 окт 2021, 09:13
7ef4447
Код
Авторство
О чём код?
import React from 'react'; import ReactDOM from 'react-dom'; import { useForm, FormProvider, useFormContext } from 'react-hook-form'; export default function App() { const methods = useForm(); const { register, handleSubmit } = methods; return ( <FormProvider {...methods}> <form onSubmit={handleSubmit((data) => console.log(data))}> <label>Test</label> <input {...register('test', { required: true })} /> <label>Nested Input</label> <Test /> <input type="submit" /> </form> </FormProvider> ); } function Test() { const data = useFormContext(); return <input {...data.register('bill')} />; }