Javascript 我在REACT JS中使用useForm,但在REACT JS中的第一次ONCHANGE函数中得到的错误输入值不起作用
我正在使用带有钩子的REACT JSJavascript 我在REACT JS中使用useForm,但在REACT JS中的第一次ONCHANGE函数中得到的错误输入值不起作用,javascript,reactjs,react-hooks,react-bootstrap,Javascript,Reactjs,React Hooks,React Bootstrap,我正在使用带有钩子的REACT JS import useForm from "react-hook-form"; const { handleSubmit, register, errors } = useForm(); <Form className="sign-up-form" onSubmit={handleSubmit(onSubmit)}> // form start <Col md={12} mb={3}>
import useForm from "react-hook-form";
const { handleSubmit, register, errors } = useForm();
<Form className="sign-up-form" onSubmit={handleSubmit(onSubmit)}> // form start
<Col md={12} mb={3}>
<label htmlFor="visatype">Visa Type</label>
<div className="form-group">
<select className="custom-select form-control"
name="visa_type_id"
value={ VisaTypeId }
ref={register({ required: true })}
onChange={e => setVisaTypeId(e.target.value)}
required>
<option value="">
Select...{" "}
</option>
{DynamicOptions(visaTypes)}
</select>
<div className="invalid-feedback">
{errors.visa_type_id && 'Visa Type is required.'}
</div>
</div>
</Col>
从“react hook form”导入useForm;
const{handleSubmit,register,errors}=useForm();
//形式开始
签证类型
setVisaTypeId(e.target.value)}
必需>
选择…{“}
{dynamiccopions(visaTypes)}
{errors.visa_type_id&&“需要签证类型”。}
我正在使用此
ref={register({required:true})}
进行验证,我正在从select getting error first time value not selected中选择值您是否仅复制了代码的几个部分,因为它似乎存在一些问题?e、 g.setVisaTypeId
和onSubmit
似乎在任何地方都没有定义,而且您似乎混淆了您传统上使用的对输入进行反应的方式以及软件包希望您这样做的方式:从他们的repo中查看此演示,他们只会向选择的输入传递一个引用,而不会显式地设置一个on-change处理程序所以你们看起来很奇怪?谢谢你们的回复。我想用这种方式设置默认值。汤姆芬尼有什么建议吗