首页 > 解决方案 > 在反应中使用带计时器的获取

问题描述

我希望我的计时器每 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);
};

标签: reactjstimerfetch

解决方案


推荐阅读