首页 > 解决方案 > react组件刷新时报错

问题描述

我有一个 react typescript 组件,它具有以下 componentDidMount 方法:

componentDidMount() {
    ComponentFields.get(this.ComponentName)
        .then(activeFields => {
            this.setState({ activeFields });
        });
}

它有一个带有以下字段的状态接口

export interface ISettingsPageState {
    activeFields: Dictionary<IComponentField>,
}

接口在哪里IComponentFieldComponentFields.get(componentName: string)是一个静态方法,它返回一个Promise<IDictionary<IComponentField>>.

第一次加载时它工作正常,但是当我刷新页面时,该setState方法componentDidMount抛出以下异常:

未捕获的 DOMException:无法在“节点”上执行“插入前”:要插入新节点的节点不是该节点的子节点。

任何人都知道可能导致这种情况的原因是什么?

标签: reactjstypescript

解决方案


事实证明,这是一个子组件抛出错误。即使setState在线上抛出异常,问题出在我的render方法中。如果有人有同样的问题,我建议看一下render方法,看看出了什么问题。


推荐阅读