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