I'm beginning with redux-saga
. I can't figure out what I do wrong.
webpack
compile succeeded. My app can run, but chrome gives me this error.
And dispatch action doesn't work.
node v6.6.0
saga/Beginning.js
:
import { call, put, takeEvery, takeLatest } from 'redux-saga/effects';
//api service
const api = 'http://it-ebooks-api.info/v1';
const service = {};
service.fetchBook = function(query) {
const url = `${api}/search/${query}`;
return fetch(url).then(res => res.json());
};
function* fetchBook(action) {
try {
const books = yield call(service.fetchBook, action.payload.query);
yield put({ type: 'BOOK_FETCH_SUCCEEDED', books });
} catch (e) {
yield put({ type: 'BOOK_FETCH_FAILED', message: e.message });
}
}
function* watchFetchBook() {
yield takeEvery('BOOK_FETCH_REQUESTED', fetchBook);
}
function* watchFetchBook() {
yield takeLatest('BOOK_FETCH_REQUESTED', fetchBook);
}
export default watchFetchBook;
saga/index.js
import { fork } from 'redux-saga/effects';
import Beginning from './Beginning';
export default function* root() {
yield [fork(Beginning)];
}
takeLatest
doesn't belongs to Redux Saga effects (see reference), you have to import it usinginstead of