【发布时间】:2020-11-20 14:03:30
【问题描述】:
从 'react' 导入 React, {Component};
从“react-redux”导入{连接};
从“redux”导入 {bindActionCreators};
import * as categoryActions from '../../redux/actions/categoryActions';
从 'reactstrap' 导入 { ListGroup, ListGroupItem };
从“reactstrap”导入 {Badge};
类 CategoryList 扩展组件{
componentDidMount(){
this.props.actions.getCategories()
}
selectCategory=(类别)=>{
this.props.changeCategory(category)
}
渲染(){
返回(
类别
{this.props.categories.map(category =>(
onClick={()=> this.selectCategory(category)} key={category.id}> {category.categoryName} ))} ); } } 函数 mapStateToProps(state){ 返回{ currentCategory:state.changeCategoryReducer, categories:state.CategoryListReducer } } 函数 mapDispatchToProps(dispatch){ 返回{ 行动:{ getCategories:bindActionCreators(categoryActions.getCategories,dispatch), changeCategory:bindActionCreators(categoryActions.changeCategory,dispatch), } }; } 导出默认连接(mapStateToProps,mapDispatchToProps)(CategoryList)
【问题讨论】:
-
为您的问题添加详细信息。