因此,我正在尝试将ExtReact的存储解析为Reducer的组件(遵循以下说明:http://docs.sencha.com/extreact/6.5.0/guides/extreact_stores_in_flux.html#extreact_stores_in_flux_-_option_1__in_the_redux_store)。但是似乎,我无法通过化简器传递状态(即我正在传递未定义的存储和数据状态),即使我在consol.log入化简中的存储和数据对象时也得到了具体的值。值得一提的是,reducer已添加到index.js CombineReducer函数中,因此可以读取它,这不是问题。
因此,这些是代码中最重要的部分:
减速器:
export function usershortcuts(state = initialState, action){
switch(action.type){
case types.USER_SHORTCUT_FETCH_DATA_SUCCESS:{
console.log("User shortcut store = state.userShortCutStore); // I am getting a concrete result
state.userShortCutData = state.userShortCutStore.getData();
console.log("User shortcut data = " + state.userShortCutData); //I am getting a concrete result
return{...state};
}
default:{
console.log(state.userShortCutStore);
return {...state};
}
}
}
初始状态:
export default {
/* User shortcuts store. */
userShortCutStore: userShortcutStore,
userShortCutData: []
}
Index.js:
const store = configureStore();
store.dispatch(usershortcutFetchDataThroughStore());
launch(
<Provider store = {store}>
<HashRouter>
<Switch>
{/* <Route path="/" name="Home" component={TextEditor}/>*/}
<Route path="/" name="Home" component={Full}/>
</Switch>
</HashRouter>
</Provider>
);
Header内部的ShortcutComponent,内部
class ShortcutComponent extends Component{
constructor(props){
super(props);
this.state={
userShortCutStore: null,
userShortCutData: []
}
}
componentDidMount(){
this.setState({
userShortCutStore: this.props.userShortCutStore,
userShortCutData: this.props.userShortCutData
})
}
render(){
const userShortCutStore = this.state.userShortCutStore;
const userShortCutData = this.state.userShortCutData;
console.log("Store = " + userShortCutStore); //undefined
console.log("User shortcut data = " + userShortCutData); //undefined
return(
/* .... */
)
}
}
const mapStateToProps = (state) => {
return {
userShortCutStore: state.userShortCutStore,
userShortCutData: state.userShortCutData
}
};
export default connect(mapStateToProps) (ShortcutComponent);
最佳答案
const mapStateToProps = (state) => {
return {
userShortCutStore: state.usershortcuts.userShortCutStore,
userShortCutData: state.usershortcuts.userShortCutData
}
};
关于javascript - 为什么Reducer的初始状态没有传递到连接的组件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49816311/