Mini-note.
Today i need to change 1 property to true and after 2 seconds to false.
At first I thought to solve the problem head-on. And I google something like "setTimeout in redux-saga".
function* changeProp() {
yield put({ type: SET_SOME_PROP, payload: true });
setTimeout(function*() {
yield ({ type: SET_SOME_PROP, payload: false });;
}, 2000);
}
But it's not working. Moreover, this example was in the first place in Google's results. Second example work good, and so simply.
function* changeProp() {
yield put({ type: SET_SOME_PROP, payload: true });
yield delay(2000);
yield put({ type: SET_SOME_PROP, payload: false });
}
Sometimes the obvious solutions are much more concise and we just need to look somewhere other than the first solution.