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

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 the 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 6287

Trending Articles



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