Javascript TypeError:无法读取属性';groupsUrl';未定义的

Javascript TypeError:无法读取属性';groupsUrl';未定义的,javascript,reactjs,Javascript,Reactjs,试图每5秒从我的db api更新一次我的状态,但我得到一个错误,即状态没有定义,即使它是 我知道setState是异步的,但在componentDidMount中,它可以读取状态,因此根据我的逻辑,如果componentDidMount调用ResetState,它肯定能够读取状态 class Groups extends Component { state = { groups : {}, categories : ["id", "name", "last fault", "

试图每5秒从我的db api更新一次我的状态,但我得到一个错误,即状态没有定义,即使它是

我知道setState是异步的,但在componentDidMount中,它可以读取状态,因此根据我的逻辑,如果componentDidMount调用ResetState,它肯定能够读取状态

class Groups extends Component {
  state = {
    groups : {},
    categories : ["id", "name", "last fault", "active"],
    groupsInfoList : [],
    enabledGroupsInfoList : [],
    disabledGroupsInfoList : [],
    groupsUrl : 'http://my.api.server/groups'
  }

  componentDidMount() {
    fetch(this.state.groupsUrl)
    .then(res => res.json())
    .then((data) => {
      var groups_object = data['result']
      this.setStates(groups_object)
      this.reSetStates()
    })
    .catch(console.log)
  }

  reSetStates(){
    fetch(this.state.groupsUrl)
    .then(res => res.json())
    .then((data) => {
      var groups_object = data['result']
      this.setStates(groups_object)
    })

    .catch(console.log)

    setTimeout(this.reSetStates, 3000);
  }

,请更改此选项

reSetStates(){
致:


你能再解释一下吗?或者可以将链接发送到我可以阅读此问题的地方?@amos baron,已经添加,请看一看,这是基于react类的组件的一个非常常见的问题。
reSetStates = () => {