How to solve the react memory leak?

clipboard.png

this._isMounted


clipboard.png

my requirement is to trigger the topImgs () method after the component is mounted, get the data list from the back end, and then assign the list to topImgsList.

Gods, please take a look. What went wrong?

Mar.11,2021

cause of the problem: before the asynchronous request is returned in topImgs , your component is already unmount . At this point, if you call setState again, you will report this error.

solution:

constructor() {
    super();
}
componentWillUnmount() {
    this.xhr && this.xhr.abort();
}
topImgs() => {
    this.xhr = React.axios();
}
Menu