redux-saga, TypeError: (0 , _effects.takeLatest) is not a function?

redux-saga, TypeError: (0 , _effects.takeLatest) is not a function?

我从 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)];
}

takeLatest 不属于 Redux Saga 效果 (see reference),您必须使用

导入它
import { takeLatest } from 'redux-saga'

而不是

import {takeLatest} from 'redux-saga/effects';

视情况而定,

if redux-saga version < 0.14 then

import { takeEvery, takeLatest, throttle } from 'redux-saga';

其他

import { takeEvery, takeLatest, throttle } from 'redux-saga/effects';

reference:

import { takeEvery, takeLatest, throttle } from 'redux-saga' was deprecated already since 0.14 which got out nearly a year ago.