this.setState()不是函数

时间:2019-12-16 03:28:55

标签: reactjs react-native

1 个答案:

答案 0 :(得分:0)

这是一个范围问题,用这样的箭头函数替换函数回调:

apiServer.getBalance(myData.token, myData.id, response => {
  if (response.success) {
    console.log("Balance success");
    balance = response.success.balance;
    this.setState({ balance: response.success.balance });
  } else {
    //login failed
    console.log("failed");
  }
});

快乐的编码。