Error: Reducer "auth" returned undefined when handling "@@INIT" action. To ignore an action, you must explicitly return the previous state
Error: Reducer "auth" returned undefined when handling "@@INIT" action. To ignore an action, you must explicitly return the previous state
无法弄清楚我在这方面出了什么问题。只是尝试为我的项目实践设置基本的 ducks 和 saga。
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)
];
}
谁能解决这个错误?
您需要return默认情况下的状态:
const auth = (state = null, action) => {
switch (action.type) {
default:
console.log('Hello World')
return state;
}
};
无法弄清楚我在这方面出了什么问题。只是尝试为我的项目实践设置基本的 ducks 和 saga。
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)
];
}
谁能解决这个错误?
您需要return默认情况下的状态:
const auth = (state = null, action) => {
switch (action.type) {
default:
console.log('Hello World')
return state;
}
};