I want to show on a generator function a console log statement but it doesnt work.
Why?
import { all, take } from 'redux-saga/effects';
function* authFetch() {
console.log('HI');
}
function* watcher() {
while(true) {
yield take("FETCH_REQUEST", authFetch);
}
}
export default function* () {
yield all([watcher()]);
}
If I edit my generator watcher function like this then it works:
function* watcher() {
while(true) {
yield take("FETCH_REQUEST", authFetch);
yield call(authFetch, '');
}
}
but I saw a lot of codes where there a no call only a take was there. Why my first code not works? I get no console.log('Hi');
takeonly expects one argument: the action type or pattern to wait for. So the second argument has no effect.takewill pause until that action happens, and then it resumes your saga on the next line, which is where you put any code you want to run afterwards.You may be thinking of other helper methods like
takeEveryandtakeLatest. For those, they will never move on to the next line, since they continue listening forever (unless cancelled). So for them, the second argument specifies which saga to fork when the action happens.