这是与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);
2条答案
按热度按时间a6b3iqyw1#
这实际上是指向云状态域的直接选择器
我认为此处您遗漏了一个步骤,您应该将domain替换为cloud,以便选择高级对象
6rqinv9w2#
你应该只使用状态只是删除
.get('cloud')
部分const selectCloud = (state) => state;
个const makeSelectCloudName = () => createSelector( selectCloud, (cloudState) => cloudState.get('domain') );
对我很有效!