如何在setTimeout中访问道具?

时间:2020-01-08 13:32:06

标签: javascript react-native

我正在尝试从keyboardDidHide内部的props访问函数,但是我需要延迟工作:

  componentDidMount() {
    this.keyboardDidHideListener = Keyboard.addListener(
      'keyboardDidHide',
      () => this._keyboardDidHide(),
    );
  }

  _keyboardDidHide() {
    setTimeout(function() {
      this.props.closeModal();
    }, 500);
  }

但是当我关闭键盘时:

TypeError: undefined is not an object (evaluating 'this.props')

但是,如果我删除,超时效果很好。如何在延迟内执行我的this.props.closeModal()

0 个答案:

没有答案