reactjs - formik onChange 不能异步工作
问题描述
name: Yup.string()
.required(),
});
const {
errors,
touched,
getFieldProps,
handleChange,
} = formik;
function onChange(e) {
if (Object.keys(errors).length === 0) {
**(HERE I HAVE errors.length 0, despite this my input is empty and is required, so I shuld have errors here. I have error here, but with delay, )**
dispatch(setInvitationConfigParam({ name: e.target.name, value: e.target.value }));
}
handleChange(e);
}
<InputWrapper>
<TextInput
customClass="input"
error={false}
textFieldProps={{
label: t('configurationForm.settings.nameConfiguration'),
error: hasErrors('name', errors, touched),
helperText: getErrors('name', errors, touched),
...getFieldProps('name'),
onChange,
}}
tooltipTitle={t('configurationForm.settings.nameConfigurationDescription')}
/>
我想要什么以及为什么我有问题。
每次用户更改他的输入名称时,我都想发送调度函数,但是如果输入名称为空,我不想发送调度。
问题是:对象errors
显示错误有延迟。我怎么能errors
没有交易?
解决方案
推荐阅读
- html - 如何将这些导航项向右移动?
- google-cloud-platform - WRITE_TRUNCATE 处置表元数据更新问题
- android - 厚度比率的默认值是如何工作的?
- python-3.x - TensorFlow Lite:运行时错误
- javascript - React - 错误:重新渲染太多。React 限制渲染次数以防止无限循环
- azure-ad-b2c - Azure AD B2C 电话 OTP 验证
- lua - LUA:#table 键引用突然改变表条目
- python - 在每个 X 循环中使用 Python 和 Pandas 保存到 excel
- php - 根据来自另一个数组的二进制值从一个数组中选择一个或多个值
- gitlab - 如何在 Gitlab 中为 Java 设置代码质量插件?