Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call redux-saga action continuously after every 60 seconds

I'm working on a situation where I need to call single API continuously after every 60 seconds

My concern is how should I call the same API request using redux-saga

I'm using the normal redux-saga action, for example, get the list of employee, which fetches the list of employee every 60 seconds

Using redux-saga, react-redux and react

like image 792
Manav Pandya Avatar asked Nov 01 '25 11:11

Manav Pandya


1 Answers

import { delay } from 'redux-saga';
import { call, put, takeLatest, all } from 'redux-saga/effects';


export function* fetchContinuously(action) {
  yield call(api);

  yield call(delay, 60000);

  yield put({ type: "FETCH_CONTINUOUSLY" })
}

function* actionWatcher() {
  yield takeLatest('FETCH_CONTINUOUSLY', fetchContinuously)
}


export default function* rootSaga() {
  yield all([
    actionWatcher(),
  ]);
}
like image 121
Gabriel Ferrarini Avatar answered Nov 03 '25 03:11

Gabriel Ferrarini