其他分享
首页 > 其他分享> > react报错this.setState is not a function

react报错this.setState is not a function

作者:互联网

改变react组件的state值,通过setSate来修改

实际使用中发现报错 

原因;

export class VenProductListTabs extends React.Component<any> {
  constructor(props) {
    super(props);
    this.state = {refreshFlag: true};
    this.change=this.change.bind(this)//将this传入 否则会找不到this 从而报错
  }
change(){
  let refreshFlag=this.state.refreshFlag;
  this.setState({
    refreshFlag: !this.state.refreshFlag
  });
}
  render() {
    return (
      <Tabs>      </Tabs>
    );
  }
}

  

标签:function,react,state,报错,props,refreshFlag,change,setState
来源: https://www.cnblogs.com/GoTing/p/15965733.html