redux React样板文件:substate.get不是一个函数

hpxqektj  于 2022-11-12  发布在  React
关注(0)|答案(2)|浏览(214)

这是与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);

在我的容器/选择器. js中

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

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

在我的容器中/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);
a6b3iqyw

a6b3iqyw1#

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

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

我认为此处您遗漏了一个步骤,您应该将domain替换为cloud,以便选择高级对象

const makeSelectCloudName = () => createSelector(
  selectCloud,
 // Select high level cloud array
  (cloudState) => cloudState.get('cloud')
);
6rqinv9w

6rqinv9w2#

你应该只使用状态只是删除.get('cloud')部分
const selectCloud = (state) => state;
const makeSelectCloudName = () => createSelector( selectCloud, (cloudState) => cloudState.get('domain') );
对我很有效!

相关问题