axios - 如何使用 yup 和 react-hook-form 逐步验证?
问题描述
const schema = yup.object().shape({
email: yup
.string()
.required()
.email('wrong email.')
.test('unique email', 'already using', async (value) => {
try {
const res = await axios.post('/accounts/emailcheck', { email: value });
return res.data.possible;
} catch (err) {
console.error(err);
}
}),
})
const { register, handleSubmit, formState: { errors } } = useForm({ mode: 'onBlur', resolver: yupResolver(schema) });
我只想使用 axios(需要,电子邮件)是可以的。但它始终适用于Blur。
如何使用 yup 和 react-hook-form 逐步验证?
解决方案
推荐阅读
- python - 构建数据矩阵时如何处理“索引越界”?
- anaconda - conda-forge 存储库是否需要 Anaconda 商业版许可证?
- php - Google Big Query insertAll() 返回成功结果,但表为空
- jenkins - 将扩展选择参数值从一个作业传递到 Jenkins 管道中的另一个远程作业
- haskell - 使用 Gloss 时有没有办法让原点位于左上角
- python - 在 Matplotlib 文本类中将两个列表组合在一起并进行排序
- postgresql - 简单的 v-model 在 false 时不会消失
- tensorflow - 使用 ML Kit 检测视频中有趣的部分
- selenium - 用于从网页读取并输入到 Windows 应用程序的 Python 应用程序。python可以处理吗?
- javascript - 动态添加 javascript 自定义事件并正确触发它们