reactjs - 在反应中使用带计时器的获取
问题描述
我希望我的计时器每 1 秒从一些 url 获取数据。
这段代码对吗?
//. let counter = 0;
let btn = () => {
let mTimer = setInterval(() => {
// fetch data from url
// counter++;
}, 1000);
/* what thing are using here until my timer end?
for example I used a while loop but timer not work successfully!
while(counter < 10){
console.log("counter : " + counter);
}
*/
clearInterval(mTimer);
};
解决方案
推荐阅读
- node.js - 如何使用 React Hooks 将 React.js 与后端一起使用,以及如何使用 heroku 部署它?
- node.js - 使用 http.get() 时无法绑定到 IPv6 localAddress - 错误:绑定 EINVAL
- c++ - 在地图中插入一对时,C++ 是否需要额外的代码?
- java - 飞碟不显示pdf中的图像
- python - 在python中使用multiproccesing时如何访问全局变量?
- node.js - 查询嵌套数组中的日期范围不起作用
- python - 元组列表中的比较
- snowflake-cloud-data-platform - 将多个文件类型中的数据加载到同一个雪花表中?
- python - 我将如何为某些列获取逐行平均值,同时在我的数据框中保留其他列?
- javascript - 无法在 jQuery 中更改 div 的背景图像