reactjs - react组件刷新时报错
问题描述
我有一个 react typescript 组件,它具有以下 componentDidMount 方法:
componentDidMount() {
ComponentFields.get(this.ComponentName)
.then(activeFields => {
this.setState({ activeFields });
});
}
它有一个带有以下字段的状态接口
export interface ISettingsPageState {
activeFields: Dictionary<IComponentField>,
}
接口在哪里IComponentField
。ComponentFields.get(componentName: string)
是一个静态方法,它返回一个Promise<IDictionary<IComponentField>>
.
第一次加载时它工作正常,但是当我刷新页面时,该setState
方法componentDidMount
抛出以下异常:
未捕获的 DOMException:无法在“节点”上执行“插入前”:要插入新节点的节点不是该节点的子节点。
任何人都知道可能导致这种情况的原因是什么?
解决方案
事实证明,这是一个子组件抛出错误。即使setState
在线上抛出异常,问题出在我的render
方法中。如果有人有同样的问题,我建议看一下render
方法,看看出了什么问题。
推荐阅读
- amazon-web-services - 使用不是主键的索引的 Dynamo DB 查询
- javascript - 如何使用 JavaScript 在特定部分中获取随机 css 左侧和顶部值?
- c# - 提交后ASP.Net白页死机
- scala - Scala - 为什么函数返回 Unit 而不是 RDD?
- sql - 从数据库中获取所有表,如果表有一些记录存在
- database - 此 EER 图是否适合我的应用程序?
- rocket.chat - 在 Android Studio 3.2-beta 1 中运行 Rocket chat kotlin sdk 时,gradle build 失败并抛出错误
- php - jquery min form-error 类在 cakephp 模型验证后隐藏我的表单控件
- c++ - 如何关闭一大块 Lua 代码
- mysql - 具有修改的列值而不重新创建表的范围分区表