美文网首页
[componentWillUnmount ]React组件销毁

[componentWillUnmount ]React组件销毁

作者: Cooliean | 来源:发表于2020-04-19 18:00 被阅读0次

react一直报这个错误:Can’t perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.

原因:

通常是 react 组件已经从 DOM 中移除(有时候是热更新引起的),但是我们在组件中做的一些异步操作还未结束,如:接口调用或者是一个setState的异步操作等,当其完成时,而此时我们已经将改组件dom移除,从而导致上述问题。

解决办法:

componentWillUnmount() {
  this.setState = (state, callback) => {
    return
  }
}

相关文章

  • [componentWillUnmount ]React组件销毁

    react一直报这个错误:Can’t perform a React state update on an unm...

  • react组件的生命周期

    组件的生命周期 组件在react的生命周期中主要经历三个阶段:实例化、存在期和销毁时。React.js在组件生命周...

  • React组件生命周期

    react组件生命周期一个React组件的生命周期分为实例化,存在期,销毁 实例化 组件在客户端被实例化,第一次被...

  • React 生命周期

    函数式组件肯定是无状态组件,类组件可以是无状态组件也可以是有状态组件 生命周期:即react实例从创建到销毁的执行...

  • React 生命周期

    函数式组件肯定是无状态组件,类组件可以是无状态组件也可以是有状态组件 生命周期:即react实例从创建到销毁的执行...

  • react 组件销毁事件记录

  • React组件生命周期

    React组件提供了生命周期的钩子函数去响应组件不同时刻的状态,组件的生命周期如下:实例化、存在期、销毁期

  • 《图解React》- 第六节 组件生命周期

    组件的从创建到销毁的过程,称之为生命周期。在使用react组件时,每个组件为了让你更好的控制组件都提供了"生命周期...

  • React生命周期

    react生命周期分为三个阶段,初始化,运行中,销毁。依次执行。 getDefaultProps:组件想要拥有默认...

  • React组件的生命周期

    React组件生命周期4个阶段:创建阶段、实例化阶段、更新阶段、销毁阶段 【创建阶段】● getDefaultPr...

网友评论

      本文标题:[componentWillUnmount ]React组件销毁

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