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
?
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
?
- please explain more we did not get your point – Prakash Karena Commented Jan 17, 2020 at 8:46
-
What are you trying to achieve? How do you use
onDisplayAlert
? – x00 Commented Jan 17, 2020 at 8:47 - Is the answer of @alex2007v somehow do not suit you? – x00 Commented Jan 17, 2020 at 16:27
1 Answer
Reset to default 11this is what you need
export function* onDisplayAlert({ payload }: any) {
payload.id = getUniqueID();
yield put(setAlert(payload));
yield delay(3000);
yield put(removeAlert(payload.id));
}