The fetchBooks
generator function takes
the action and fetches books per the category specified.
function* fetchBooks() {
while (true) {
const { payload:{ bookCategory }} = yield take(FETCH_BOOKS);
// receive and perform external fetch
const books = fetchMyBooks(bookCategory);
!books
? yield put({ type: FAILURE })
: yield books
}
}
Inside another generator function I am trying to call fetchBooks
like so
function* handleSomethingAndThenFetch() {
// ...doing soemthing... then
const books = yield put({ type: fetchBooks, payload:{ 'FICTION' }});
}
Using the fetchBooks
generator function, how can I return the value of the books? I tried using this:
const books = yield call(fetchBooks, 'FICTION');
but I am trying to avoid changing the fetchBooks
books function. Is there another way?