首页 > 解决方案 > 添加额外的类字段会引发流类型错误

问题描述

我尝试按照React 文档每隔 x 秒调用一个函数,如下所示:

componentDidMount () {
  const { dispatch, match } = this.props
  dispatch(loadPipelineExecutions(match.params.pipelineId))
  this.reloadExecutions = setInterval(
    () => dispatch(loadPipelineExecutions(match.params.pipelineId)),
    3000
  )
}

componentWillUnmount () {
  clearInterval(this.reloadExecutions)
}

但我收到一个流类型错误,提示:无法分配到setInterval(...)this.reloadExecutions因为.reloadExecutionsTableExecutionsContainer

这是正常的流动行为吗?

标签: javascriptreactjs

解决方案


推荐阅读