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

相關文章
相關標籤/搜索