首页 > 解决方案 > Redux mapStateToProps 到类反应组件

问题描述

我有这个代码

import {connect} from 'react-redux';
import { createStructuredSelector } from 'reselect';

class GroupsPage extends React.Component {
  constructor(props){
    super(props)
  }

  render(){
    return();
}
};

const mapStateToProps = createStructuredSelector({
  groups: selectGroups
})

export default connect(mapStateToProps)(GroupsPage);

我的问题是,如何将组对象从 mapStateToProps 获取到 GroupsPage 组件中?

标签: reactjsreact-redux

解决方案


您的状态将在组件道具中,只需在构造函数中调用 console.log;

 console.log(props.groups)

推荐阅读