Pass item data to a react modal

前端 未结 3 1587
伪装坚强ぢ
伪装坚强ぢ 2021-02-14 23:46

I have a map that render few items and one of its line is below

 this.setState({\"openDeleteModal\":true)}>Delete
3条回答
  •  情深已故
    2021-02-15 00:18

    Copying over my answer from How to pass props to a modal

    Similar scenario

    constructor(props) {
    
        super(props)
    
    
        this.state = {
          isModalOpen: false,
          modalProduct: undefined,
        }
    }
    
    //****************************************************************************/
    
    render() {
    
        return (
            

    Bag

    {this.state.isModalOpen & ( this.setState({ isModalOpen: false, modalProduct: undefined}) deleteProduct={ ... } /> ) {bag.products.map((product, index) => (
    {product.name}
    £{product.price}
    Quantity:{product.quantity} // <----
    ))} ) } //****************************************************************************/ decrementQuantity(product) { if(product.quantity === 1) { this.setState({ isModalOpen: true, modalProduct: product }) } else { this.props.decrementQuantity(product) } }

提交回复
热议问题