Skip to content

control

掌控表单

</> control: Object

该对象包含将组件注册到 React Hook Form 中的方法。

¥This object contains methods for registering components into React Hook Form.

RULES

重要的:不要直接访问该对象内的任何属性。仅供内部使用。

¥Important: do not access any of the properties inside this object directly. It's for internal usage only.

示例:

¥Examples:


import React from "react"
import { useForm, Controller } from "react-hook-form"
import { TextField } from "@material-ui/core"
type FormInputs = {
firstName: string
}
function App() {
const { control, handleSubmit } = useForm<FormInputs>()
const onSubmit = (data: FormInputs) => console.log(data)
return (
<form onSubmit={handleSubmit(onSubmit)}>
<Controller
as={TextField}
name="firstName"
control={control}
defaultValue=""
/>
<input type="submit" />
</form>
)
}
import { useForm, Controller } from "react-hook-form"
function App() {
const { control } = useForm()
return (
<Controller
render={({ field }) => <input {...field} />}
name="firstName"
control={control}
defaultValue=""
/>
)
}
React Hook Form 中文网 - 粤ICP备13048890号