【问题标题】:I cannot add categories to the site REACTJS我无法向网站 REACTJS 添加类别
【发布时间】: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)

【问题讨论】:

  • 为您的问题添加详细信息。

标签: reactjs redux


【解决方案1】:

购物车总结 进口 { 不受控制的下拉, 下拉切换, 下拉式菜单, 下拉项, 导航项, 导航链接, 徽章 } 来自'reactstrap'; 从'redux'导入{bindActionCreators}; 从 '../../redux/actions/cartActions' 导入 * 作为 cartActions; 从“反应”导入反应,{组件}; 从'react-redux'导入{连接}; 类 CartSummary 扩展组件 { 渲染空(){ 返回 ( 塞蒂尼兹博斯 ) } 渲染摘要(){ 返回 ( 塞佩蒂尼兹

                <DropdownMenu right>
                    {
                        this.props.cart.map(cartItem => (

                            <DropdownItem key={cartItem.product.id}>
                                 <Badge color ="danger" onClick={()=>this.props.actions.removeFromCart(cartItem.product)}> x </Badge>
                                {cartItem.product.productName}

                            <Badge color ="success"> {cartItem.quantity} </Badge>
                            </DropdownItem>
                        ))
                    }
                    <DropdownItem divider />
                    <DropdownItem>
                        sepete git
              </DropdownItem>
                </DropdownMenu>
            </UncontrolledDropdown>
        )
    }
    render() {
        return (
            <div >
                {
                    this.props.cart.length > 0 ? this.renderSummary() : this.renderEmpty()
                }

            </div>
        )
    }
}
function mapStateToProps(state) {
    return {
        cart: state.cartReducer
    }
}
    function mapDispatchToProps(dispatch) {
        return {
            actions:{
                removeFromCart:
                bindActionCreators(
                    cartActions.removeFromCart,
                    dispatch)
            }

        }
    }
export default connect(mapStateToProps,mapDispatchToProps)(CartSummary)

【讨论】:

    猜你喜欢
    • 2014-04-12
    • 2020-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-05
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    相关资源
    最近更新 更多