使用redux,当状态树中的状态有效更改时,为什么mapStateToProps()在道具中不显示状态?

时间:2018-07-28 05:41:00

标签: reactjs redux react-redux

我正在尝试通过mapStateToProps()将状态传递为props,即使状态更改反映在状态树(redux工具检查器)中,并且随着操作有效负载成功传递了“数据”登录reducer.js,状态没有作为props传递到我的容器中。

我的reducer.js:

import { fromJS } from 'immutable'
import { GOT_INDUSTRY_DATA } from './constants.js';

const initialState = fromJS({
    data: []
})

function industryDataReducer(state = initialState, action){
    switch (action.type) {
        case GOT_INDUSTRY_DATA: {
            const { data } = action
            console.log('reducer data',data)
            return state.set('data', fromJS(data))
        }
    default:
      return state
  }
}

export default industryDataReducer

在我的容器中

    export class IndustryPage extends React.PureComponent { 

     render(){
      const { data } = this.props
      console.log(data)
      return{
        ...
      }
     }
    }

    function mapStateToProps({data}) {
     return {
      data
     }
    }

    const withConnect = connect(mapStateToProps, mapDispatchToProps)
    const withSaga = injectSaga({ key: 'industry', saga })
    const withReducer = injectReducer({ key: 'industry', reducer })

    export default compose (
     withStyles(styles),
     withSaga,
     withReducer,
     withConnect
    )(IndustryPage);

screenshot of data in state tree

0 个答案:

没有答案