Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)];
}
like image 423
slideshowp2 Avatar asked Dec 15 '16 03:12

slideshowp2


2 Answers

takeLatest doesn't belongs to Redux Saga effects (see reference), you have to import it using

import { takeLatest } from 'redux-saga'

instead of

import {takeLatest} from 'redux-saga/effects';
like image 136
Freez Avatar answered Nov 15 '22 03:11

Freez


It depends,

if redux-saga version < 0.14 then

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

else

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.

like image 34
joshweir Avatar answered Nov 15 '22 04:11

joshweir