react-admin - React-admin - 在渲染不同的组件(`SelectInput`)时无法更新组件(`xxx`)
问题描述
反应管理员 3.8.4
我正在有条件地渲染一些表单字段,并且这些字段有一些验证。因此,我在下面收到此错误:
Warning: Cannot update a component (nameOfTheComponent) while rendering a different component
(SelectInput). To locate the bad setState() call inside SelectInput, follow the stack trace
as described in...
我已经阅读了有关该问题的一些解释,并且发现在注册这些字段时 react-final-form 调用了 setState() ,这似乎是问题所在。
我还看到 FileConfig 中有一个名为静默的修复程序,可以解决这个问题React final form silent
但我不知道我是否用错了,因为警告仍然出现。
我正在尝试做这样的事情:
const OfferVariation = ({ formData, ...rest }) => {
const form = useForm();
useEffect(() => {
return () => {
const initialState = {}
let inConstructor = true
const fieldName = "internalOffer.type"
form.registerField(fieldName, fieldState => {
if (inConstructor) {
initialState[fieldName] = fieldState
} else {
this.setState({ [fieldName]: fieldState })
}
}, { silent: true })
}
}, [])
if (flowType === "Interna") {
return (
<SelectInput
source="internalOffer.type"
label="Tipo da Oferta"
choices={offerTypes}
validate={validateArrayNotEmpty}
{...rest}
/>
)
} else if (flowType === "Externa") {
return (
<TextInput
label="Url Externa"
source="externalOffer.externalURL"
{...rest}
/>
)
}
}
};
export default OfferVariation;
有谁知道如何解决它并可以帮助我?
解决方案
推荐阅读
- redis - StackExchange.Redis.Extensions.Newtonsoft:调用之间的高时间
- python - 提高简单推送弹出“堆栈”的性能
- linux - Ubuntu 将项目添加到 /etc/rc.local
- node.js - 超出最大调用堆栈大小(node.js 中的 Web 套接字)
- android - java.lang.SecurityException: Permission Denial: writing android.support.v4.content.FileProvider uri
- javascript - 如何将javascript应用于多个按钮组
- ios - 定位约束没有任何影响
- javascript - Angular 6将一个验证规则应用于所有字段的任何简单方法
- c - 递归地创建和显示人的金字塔 - C
- python - Python Marshmallow:字典验证错误