加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

setState warning

发布时间:2020-12-15 06:36:55 所属栏目:百科 来源:网络整理
导读:最近项目遇到了个奇怪的问题,代码如下 class Demo extends React.Component { constructor(props) { super(props); this.state = { value: '' }; } handleChange = (e) = { this.setState({ value: e.target.value }); }; render() { return ( input type="

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

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}/>
        );
    }
}

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

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.

于是升级 react-hot-loader 即可。

-------- 分割线

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读