Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6208

Use yield inside of setTimeOut in redux saga

$
0
0

In my react project I have the following code.

export function* onDisplayAlert({ payload }: any) {
  payload.id = getUniqueID();
  yield put(setAlert(payload));

  yield setTimeout(() => {
    yield put(removeAlert(payload.id));
  }, 3000);
}

What I want to do here is use yield inside setTimeOut callback.

yield put(removeAlert(payload.id));

But the way I have written this doesn't work.Because arrow function callback is not a generator function, so I can't use yield inside it. How can I use yield inside setTimeOut?


Viewing all articles
Browse latest Browse all 6208

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>