Uncaught Error: Reducer "usershortcuts" returned undefined during initialization

Uncaught Error: Reducer "usershortcuts" returned undefined during initialization

所以我尝试在启动应用程序之前初始化 ExtReact 的存储,以便我可以加载数据,使用 Redux 存储来更新应用程序的状态。不要被动作调用搞糊涂了,它只是用来通知 reducer 他现在可以加载 store。为此,我一直在关注本教程 (http://docs.sencha.com/extreact/6.5.0/guides/extreact_stores_in_flux.html)。但我收到此错误:

Uncaught Error: Reducer "usershortcuts" 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. 

所以这些是代码中最重要的部分:

  1. index.js(入口点):

    const store = configureStore();
    
    /* Calling of actions. */
    store.dispatch(usershortcutFetchDataThroughStore());
    
      launch(
      <Provider store = {store}>
          <HashRouter>
            <Switch>
    
             {/* <Route path="/" name="Home" component={TextEditor}/>*/}
              <Route path="/" name="Home" component={Full}/>
            </Switch>
          </HashRouter>
      </Provider>
    );
    
  2. 我的减速器:

export function usershortcuts(state = initialState, action){
        switch(action.type){
            case types.USER_SHORTCUT_FETCH_DATA_SUCCESS:
                return[...state];
        }
}
  1. 我的初始状态:
export default {
    /* User shortcuts store. */
    userShortCutStore: new Ext.data.Store({
        model: userShortcutModel,
        autoLoad: true,
        pageSize: 10,
        proxy: {
            type: 'ajax',
            reader: {
                type: 'json'
            },
            url: '/usershortcut/all/'
        }
    })
}
  1. 配置商店:
export default function configureStore() {
    return createStore(
        rootReducer,
        initialState,

        // Apply thunk middleware and add support for Redux dev tools in Google Chrome
        process.env.NODE_ENV !== "production" && window.devToolsExtension ?
            compose(applyMiddleware(thunk), window.devToolsExtension())
            :
            applyMiddleware(thunk)
    );
}

在你的 reducer 上,你需要 return 默认状态,而且你不能将状态保留为未定义,因此你需要至少将初始状态设置为空值

const initialState = null;
export function usershortcuts(state = initialState, action){
        switch(action.type){
            case types.USER_SHORTCUT_FETCH_DATA_SUCCESS:{
                return[...state];
            }
            default:{
               return state // We return the default state here
            }
        }
}