react-hook-form:如何在收到来自 api 端点的响应后显示验证消息?
react-hook-form: how to show validaton message after getting response from api end point?
为了验证以 react-hook-form 形式提交的输入,我正在做这样的事情
<input type="text" id="name" ref={register({ required: true, maxLength: 30 })} />
但那是在提交时..在我从远程 api 端点收到响应后,我需要显示一些验证消息..在相同的输入字段中...
您可以使用触发函数以编程方式触发验证:
const { trigger } = useForm();
const triggerValidation = () => {
trigger() // all fields
trigger("lastName") // specific field
}
为了验证以 react-hook-form 形式提交的输入,我正在做这样的事情
<input type="text" id="name" ref={register({ required: true, maxLength: 30 })} />
但那是在提交时..在我从远程 api 端点收到响应后,我需要显示一些验证消息..在相同的输入字段中...
您可以使用触发函数以编程方式触发验证:
const { trigger } = useForm();
const triggerValidation = () => {
trigger() // all fields
trigger("lastName") // specific field
}