如何在智能表单组件中使用 react-hook-form 验证自定义输入?
How to validate a custom input using react-hook-form in Smart Form Component?
我想使用 react-hook-form 验证输入。但我无法在寄存器中发送验证规则。如何解决这个问题
https://codesandbox.io/s/react-hook-form-smart-form-component-vpsc0
我认为这个问题已经在 Github 期得到解决:
https://codesandbox.io/s/react-hook-form-smart-form-component-17k06
你可以将规则(验证)作为 props 向下传递
<Input name="firstName" rules={{ required: true }} />
export function Input({ register, name, rules, ...rest }) {
return <input name={name} ref={register(rules)} {...rest} />;
}
我想使用 react-hook-form 验证输入。但我无法在寄存器中发送验证规则。如何解决这个问题
https://codesandbox.io/s/react-hook-form-smart-form-component-vpsc0
我认为这个问题已经在 Github 期得到解决:
https://codesandbox.io/s/react-hook-form-smart-form-component-17k06
你可以将规则(验证)作为 props 向下传递
<Input name="firstName" rules={{ required: true }} />
export function Input({ register, name, rules, ...rest }) {
return <input name={name} ref={register(rules)} {...rest} />;
}