redux-saga,TypeError:(0,_effects.takeLatest)不是函数?

时间:2016-12-15 03:07:52

标签: reactjs redux redux-saga

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

2 个答案:

答案 0 :(得分:3)

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

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

而不是

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

答案 1 :(得分:3)

取决于,

如果redux-saga版本< 0.14然后

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

其他

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

reference

  

从' redux-saga'导入{takeEvery,takeLatest,throttle}是   自0.14近一年前就已经弃用了。