javascript - Uncaught Error: Reducer "usershortcuts" returned undefined during initialization - Stack Overflow

So I am trying to initialize the store of ExtReact before launching the app so I could load data, using

So I am trying to initialize the store of ExtReact before launching the app so I could load data, using the Redux store for updating the state of the application. Don't be confused by a call of an action, it is just used to notify the reducer that he can load the store right now. I was following this tutorial for that (.5.0/guides/extreact_stores_in_flux.html). But I am receiving this error:

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. 

So these are the most important parts of the code:

  1. index.js (the entry point):

    const store = configureStore();
    
    /* Calling of actions. */
    store.dispatch(usershortcutFetchDataThroughStore());
    
      launch(
      <Provider store = {store}>
          <HashRouter>
            <Switch>
    
             {/* <Route path="/" name="Home" ponent={TextEditor}/>*/}
              <Route path="/" name="Home" ponent={Full}/>
            </Switch>
          </HashRouter>
      </Provider>
    );
    
  2. My reducer:

export function usershortcuts(state = initialState, action){
        switch(action.type){
            case types.USER_SHORTCUT_FETCH_DATA_SUCCESS:
                return[...state];
        }
}
  1. My initial state:
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. Configure store:
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 ?
            pose(applyMiddleware(thunk), window.devToolsExtension())
            :
            applyMiddleware(thunk)
    );
}

So I am trying to initialize the store of ExtReact before launching the app so I could load data, using the Redux store for updating the state of the application. Don't be confused by a call of an action, it is just used to notify the reducer that he can load the store right now. I was following this tutorial for that (http://docs.sencha./extreact/6.5.0/guides/extreact_stores_in_flux.html). But I am receiving this error:

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. 

So these are the most important parts of the code:

  1. index.js (the entry point):

    const store = configureStore();
    
    /* Calling of actions. */
    store.dispatch(usershortcutFetchDataThroughStore());
    
      launch(
      <Provider store = {store}>
          <HashRouter>
            <Switch>
    
             {/* <Route path="/" name="Home" ponent={TextEditor}/>*/}
              <Route path="/" name="Home" ponent={Full}/>
            </Switch>
          </HashRouter>
      </Provider>
    );
    
  2. My reducer:

export function usershortcuts(state = initialState, action){
        switch(action.type){
            case types.USER_SHORTCUT_FETCH_DATA_SUCCESS:
                return[...state];
        }
}
  1. My initial state:
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. Configure store:
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 ?
            pose(applyMiddleware(thunk), window.devToolsExtension())
            :
            applyMiddleware(thunk)
    );
}
Share Improve this question asked Apr 11, 2018 at 12:19 Милош РајковићМилош Рајковић 2933 silver badges14 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

On your reducer you need to return the default state , and also you cant leave the state as undefined so you need to set an initial state at the least a null value

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
            }
        }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744800211a4594445.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信