React Boilerplate:substate.get不是函数

问题描述 投票:0回答:1

这是与substate.get() is not a function using React Boilerplate相同的问题,但我没有得到这个问题的解决方案。

我想仅在一个文件中定义我的初始状态。这是初始化状态的正确方法。

我在app.js中添加了

const initialState = fromJS({
  cloud: [
    {
      machine_name: 'trust.zscaler.net',
      domain: 'Zscaler.net',
        },
      ],
    });
const history = createHistory();
const store = configureStore(initialState, history);

在我的container / selectors.js中

const selectCloud = (state) => state.get('cloud');

const makeSelectCloudName = () => createSelector(
  selectCloud,
  (cloudState) => cloudState.get('domain')
);

在我的container / index.js中

const mapStateToProps = createStructuredSelector({
  cloud: makeSelectCloudName(),
});

const mapDispatchToProps = (dispatch) => ({
  setCloud: (value) => {
    dispatch(setCloud(value));
  },
})

const withReducer = injectReducer({ key: 'cloud', reducer });
const withSaga = injectSaga({ key: 'cloud', saga });
const withConnect = connect(mapStateToProps, mapDispatchToProps);

export default compose(
  withReducer,
  withSaga,
  withConnect,
)(CloudSelect);
reactjs redux react-redux
1个回答
0
投票

这实际上是云状态域的直接选择器

const selectCloud = (state) => state.get('cloud');

我想在这里你错过了一步你应该用云替换域以选择高级对象

const makeSelectCloudName = () => createSelector(
  selectCloud,
 // Select high level cloud array
  (cloudState) => cloudState.get('cloud')
);
© www.soinside.com 2019 - 2024. All rights reserved.