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;
    }
}
阅读 5.5k
2 个回答
新手上路,请多包涵

是不是版本不一样,然后新版本给改了 我也出现了这样的错误,换成您的说方式就ok了

`

yarn redux-immutable 

`

该插件返回一个combineReducers函数,把redux的combineReducers函数替换掉即可;
如下:

import { combineReducers } from 'redux-immutable';
import { reducer as user } from '../pages/user/store';


export default combineReducers({
  user: user
});~~~~
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题