错误:处理“ @@ INIT”操作时,Reducer“ auth”返回未定义。要忽略操作,您必须显式返回先前的状态

时间:2018-07-20 09:53:14

标签: reactjs redux react-redux redux-thunk redux-saga

无法弄清楚我在这方面出了什么问题。只是尝试为我的项目实践设置基本的鸭子和传奇。

Can't figure out what I'm doing wrong in this

Ducks / auth.js

    const action = name => `/auth/${name}`;

export const FETCH = action('FETCH');

export const fetchUser = (user) => ({ type: FETCH, user });

const auth = (state = null, action) => {
  switch (action.type) {
    default:
      return console.log('Hello World');
  }
};

export default auth;

Sagas / auth.js

import {
  fork,
  takeLatest,
} from 'redux-saga/effects';
import * as actions from 'ducks/auth';

export function* fetchUser() {
  yield console.log('Hello World');
}

export function* watchFetchUser() {
  yield takeLatest(actions.FETCH, fetchUser);
}

export default function* rootSaga() {
  yield [
    fork(watchFetchUser)
  ];
}

任何人都可以解决此错误吗?

1 个答案:

答案 0 :(得分:1)

您需要在默认情况下返回状态:

const auth = (state = null, action) => {
  switch (action.type) {
    default:
      console.log('Hello World')
      return state;
  }
};