Мил*_*вић 2 javascript reactjs react-redux extreact
所以我试图在启动应用程序之前初始化 ExtReact 的存储,以便我可以加载数据,使用 Redux 存储更新应用程序的状态。不要被 action 的调用所迷惑,它只是用来通知 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.
Run Code Online (Sandbox Code Playgroud)
所以这些是代码中最重要的部分:
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>
);
Run Code Online (Sandbox Code Playgroud)我的减速机:
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.
Run Code Online (Sandbox Code Playgroud)
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>
);
Run Code Online (Sandbox Code Playgroud)
export function usershortcuts(state = initialState, action){
switch(action.type){
case types.USER_SHORTCUT_FETCH_DATA_SUCCESS:
return[...state];
}
}
Run Code Online (Sandbox Code Playgroud)
在您的减速器上,您需要返回默认状态,并且您不能将状态保留为未定义,因此您需要将初始状态设置为至少一个空值
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
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2864 次 |
| 最近记录: |