我以redux-saga
开头。我无法弄清楚我做错了什么。
webpack
编译成功。我的应用可以运行,但Chrome会给我这个错误。
调度行动无效。
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)];
}
答案 0 :(得分:3)
takeLatest
不属于Redux Saga效果(see reference),您必须使用
import { takeLatest } from 'redux-saga'
而不是
import {takeLatest} from 'redux-saga/effects';
答案 1 :(得分:3)