setState warning

最近项目遇到了个奇怪的问题,代码以下react

class Demo extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            value: ''
        };
    }

    handleChange = (e) => {
        this.setState({
            value: e.target.value
        });
    };

    render() {
        return (
            <input type="text" value={this.state.value} onChange={this.handleChange}/>
        );
    }
}

很简单的代码,然而却报了下面的错误。 。。。。。。。。。。。。。。。。git

Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the OverviewHeader component.

google 的信息提供补了什么帮助。经过二分法逐步排查了问题,最后定位到是多是 react-hot-loader 的问题,找到了个关键 issue https://github.com/gaearon/re...,最后做者说 : This is completely solved in React Hot Loader v4.github

因而升级 react-hot-loader 便可。babel

-------- 分割线this

以前项目没有相似问题。进一步分析得出,新项目是用了 babel-preset-env ,so...。google

相关文章
相关标签/搜索