while (true) {
const {payload} = yield take(CommentsActionTypes.LOAD_COMMENTS_REQUEST);
try {
const {data} = yield call(
axios.get,
/api/comments?last_days=${payload.lastDaysLimit}
);
yield put(CommentsActions.loadComments.success(data));
} catch (error) {
yield put(CommentsActions.loadComments.failure(error));
}
}
}
тут while(true) ?
я пишу саги так function* root() { yield all([ someSagas() ]) } // someSagas function* someSaga(action) { const { something } = action.payload const { response, error } = yield call(API call with 'something in body') if (error) { yield put({ type: types.SOME_ACTION_FAILURE }) } else { yield put({ type: types.SOME_ACTION_SUCCESS, payload: { something: response } }) } } export function* someSagas() { yield [ takeLatest/takeEvery(types.SOME_ACTION_REQUEST, someSaga) ] }
Обсуждают сегодня