如何解决React-admin-在渲染其他组件`SelectInput`时无法更新组件`xxx`
React-admin 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中有一个名为silent的修复程序可以解决此问题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;
有人知道如何解决它并且可以帮助我吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。