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:
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> );
My reducer:
export function usershortcuts(state = initialState, action){
switch(action.type){
case types.USER_SHORTCUT_FETCH_DATA_SUCCESS:
return[...state];
}
}
- 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/'
}
})
}
- 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:
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> );
My reducer:
export function usershortcuts(state = initialState, action){
switch(action.type){
case types.USER_SHORTCUT_FETCH_DATA_SUCCESS:
return[...state];
}
}
- 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/'
}
})
}
- 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
1 Answer
Reset to default 6On 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条)