LaterJS + useEffect多次发出函数调用

时间:2019-07-30 18:45:15

标签: javascript reactjs react-hooks laterjs

我的代码:

useEffect(() => {
    later.setInterval(
      async () => {
        console.log('refreshing...', dayjs().format('HH:mm:ss')); // eslint-disable-line 
        const refreshedCredentials = await refreshSession();
        refreshUserSession(refreshedCredentials);
      },
      later.parse.text('every 25 min'),
    );
  }, []); // eslint-disable-line

.setInterval应该:

  

每次连续执行文本计划都执行(功能)

换句话说,只要时间匹配,就运行该函数。但是,我的函数似乎要重新运行多次:

enter image description here

这会导致不必要的API请求,我担心以后会滞后于我的应用程序。有什么建议吗?

更新:

有问题的文件包装了几个反应路由器路由(MainLayout):

      <MainLayout>
          <Route
            exact
            path="/dashboard"
            component={Dashboard}
          />

          <Route
            exact
            path="/restaurant"
            component={Restaurant}
          />

          <Route
            exact
            path="/reservations"
            component={Reservations}
          />

          <Route
            exact
            path="/dishes"
            component={Dishes}
          />

          <Route
            exact
            path="/dishes/:id"
            component={Dish}
          />
        </MainLayout>

0 个答案:

没有答案