React 15 setState 下一行不起作用

React 15 setState next line does not work

action 后的 react setState 不起作用。

handleChange = () => {
    this.setState({foo: 'bar'});  < - it working 
    console.log('hellow') < - does not working, console is clean 
}

就我检查状态而言,我对状态值所做的一切都是正确的。

不知道是什么问题

----更新----

新建create-react-app的项目运行正常

不知道为什么会出现上面的问题,按常理来说也说不通,不过好像是因为项目太乱了

感谢您回答如此有限的情况。

请试试这个

handleChange = () => {
  this.setState({ foo: "bar" }, () => {
    console.log("hellow");
  });
};

您可以在setState中调用回调,如下所示

handleChange = () => {
    this.setState({foo: 'bar'}, () => {
    console.log('hellow')
}); 

}

您的代码是正确的,但您需要调用 handleChange() 方法 例如:-

componentDidMount() {
  this.handleChange();
}

handleChange = () => {
  this.setState({ foo: "bar" });
  console.log("Hello");
};