声明为空的初始状态,但在 redux 中“初始化错误期间未定义”

时间:2021-07-14 03:56:23

标签: redux

我收到键“Reducer”的切片减速器在初始化期间返回未定义错误。 我已经初始化了一个空状态。

const initialState = {
    posts: []
};

const reducer = (state = initialState, action) => {
    switch (action.type) {
        case 'GET_POSTS':
            return action.payload;
        default:
            return state;
    }
}

export default reducer;
Error: The slice reducer for key "Reducer" returned undefined during initialization. 
If the state passed to the reducer is undefined, you must explicitly return the initial state. 
The initial state may not be undefined. 
If you don't want to set a value for this reducer, you can use null instead of undefined.
▶ 3 stack frames were collapsed.
Module.<anonymous>
D:/Projects/Web/Ekart/client/src/Reducers/index.js:4
  1 | import { combineReducers } from 'redux';
  2 | import Reducer from './reducer';
  3 | 
> 4 | export default combineReducers({ Reducer });
  5 | 

请帮忙!!!

0 个答案:

没有答案
相关问题