【发布时间】:2018-08-20 09:58:16
【问题描述】:
我需要在 React 中每 30 秒轮询一次 API 以获取响应
我正在考虑调用这个方法:
poll() {
setTimeout(() => {
console.log('polling') // would hit the API here
}, 100)
}
在componentDidMount 里面,然后在里面做一个三元组什么的
但是在componentDidMount 它不喜欢我这样做
this.props.loading ? this.poll() : null
说一些关于预期功能但看到表达(linting 错误)
如何轮询 API,或者这是正确的方法吗?
【问题讨论】:
-
请分享完整的生命周期代码和构造函数
标签: javascript reactjs api polling