2

因此,我正在尝试将 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 函数中,因此可以读取它,这不是问题。

因此,这些是代码中最重要的部分:

  1. 减速器:
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};
        }
    }
}
  1. 初始状态:
export default {
    /* User shortcuts store. */
    userShortCutStore: userShortcutStore,

    userShortCutData: []
}
  1. 索引.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>
);
  1. ShortcutComponent 在 Header 里面,在里面
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);
4

1 回答 1

2
const mapStateToProps = (state) => {
    return { 
        userShortCutStore: state.usershortcuts.userShortCutStore,
        userShortCutData: state.usershortcuts.userShortCutData
    }
};
于 2018-04-13T11:56:13.583 回答