13-사가-조합
function* fetchPosts() {
yield put(actions.requestPosts())
const products = yield call(fetchApi, '/products')
yield put(actions.receivePosts(products))
}
function* watchFetch() {
while (yield take(FETCH_POSTS)) {
yield call(fetchPosts) // waits for the fetchPosts task to terminate
}
}function* mainSaga(getState) {
const results = yield all[call(task1), call(task2), ...]
yield put(showResults(results))
}Last updated
Was this helpful?