美文网首页
React Warn & Error FAQ

React Warn & Error FAQ

作者: 浩鸽鸽 | 来源:发表于2020-03-26 10:49 被阅读0次

1. instance.render is not a function

图1

没有render方法导致的。

-----

2. Can't call setState (or forceUpdate) on an unmounted component. 

  这种报错是因为组件已经销毁了(componentWillUnmount钩子函数已触发)但是还调用了组件的SetState方法。 

一般什么情况下会出现这种情况呢?

如下示例代码所示:

export class  XX extend Component{

...

componentWillMount() {

        // 划重点

       window.onclick = () => { this.setState({

           aa : 'aa,'

        })}

    }

....

}

通过上面的代码我们可以看到,组件销毁后但是挂载在window上面的 onclick事件依然生效,此时触发事件后就会引起以上warning。

相关文章

网友评论

      本文标题:React Warn & Error FAQ

      本文链接:https://www.haomeiwen.com/subject/jryttqtx.html