react-redux/immutable中getIn(['props1','props2'])无法使用
我调用时候用getin([外层,内层])报错
const mapState= (state)=>({
title:state.getIn(['detail','title']),
content:state.getIn(['detail','content'])
})
报错信息如下
×
←→1 of 2 errors on the page
TypeError: state.getIn is not a function
Function.mapState [as mapToProps]
H:/Workspace/src/pages/detail/index.js:16
13 | }
14 | }
15 | const mapState= (state)=>({
> 16 | title:state.getIn(['detail','title']),
17 | content:state.getIn(['detail','content'])
用下面的方法 外层.get(内层)就成功不报错
const mapState= (state)=>({
title:state.detail.get('title'),
content:state.detail.get('content')
})
外层reducer
import { combineReducers } from 'redux';
import { reducer as detailReducer} from '../pages/detail/store';
const reducer = combineReducers({
detail: detailReducer
});
内层reducer
import { fromJS } from 'immutable';
import * as constants from './constants';
const defaultState = fromJS({
title:'哈哈哈',
content: '哈哈哈'
})
export default ( state = defaultState, action )=>{
switch(action.type){
default:
return state;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是不是版本不一样,然后新版本给改了 我也出现了这样的错误,换成您的说方式就ok了
`
`
该插件返回一个combineReducers函数,把redux的combineReducers函数替换掉即可;
如下: