[Solved] react error: Can’t perform a React state update on an unmounted component

wrong reason:
If an asynchronous operation is performed after the component is mounted (mounted), such as an ajax request or a timer is set, and you perform a setState operation in the callback, the component has been unmounted,
At this point, the callback in the asynchronous operation is still executing, so setState does not get a value.

Solution: componentWillUnmount() when unmounting the component, clear all operations.

case:

componentDidUpdate(prevProps, prevState) {
        let _this=this;
        const { eventGis } = this.state;
        if (eventGis & amp; & amp; eventGis !== prevProps.eventGis) {
            this.timer = setInterval(function(){_this.getDistance(eventGis)}, 1000 * 30);
        }
    }


    componentWillUnmount() {
        Subscribe.unregister('EVENT_TASK', this.handler);
        this.handler = null;
        this.timer & amp; & amp; clearInterval(this.timer);
        this.timer = null;
        localStorage.removeItem('recordObj');
        this.setState=(state,callback)=>{
            return;
        }
    }

Basic knowledge to master:

componentWillMount
It will only be called once before loading and before rendering. You can call setstate in this method to change the state, and it will not cause an additional call to render
componentDidMount
It will only be called once after loading, and after rendering. From here, you can get the dom node of the component through reactDOM.findDOMNode(this)
update component trigger
componentWillReceiveProps shouldComponentUpdate componentWillupdate componentDidUpdate