• 1
  • 新人请关照

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;
    }
}
阅读 771
评论
    2 个回答
    • 3
    • 新人请关照

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

      • 1
      • 新人请关照

      `

      yarn redux-immutable 

      `

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

      import { combineReducers } from 'redux-immutable';
      import { reducer as user } from '../pages/user/store';
      
      
      export default combineReducers({
        user: user
      });~~~~
        撰写回答

        登录后参与交流、获取后续更新提醒