Last active
December 2, 2016 12:40
-
-
Save fcsonline/236a12e570c253d0547d7ae541a59880 to your computer and use it in GitHub Desktop.
Cart - CartList
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CartList extends React.Component { | |
onClickItem(event, index) { | |
this.state.setState({ | |
selected: [ | |
...this.state.selected, | |
index | |
] | |
}); | |
} | |
onClickRemove () { | |
// Go to your store and remove item | |
} | |
renderCartItem(item, index) { | |
const isPremium = item.premium ? 'premium' : ''; | |
const isSelected = this.state.selected.indexOf(index) >= 0 ? 'selected' : ''; | |
return ( | |
<li className={`${isPremium} ${isSelected}`} onClick={(event) => this.onClickItem(event, index)}> | |
<header>{item.title}</header> | |
<p>{item.description}</p> | |
<button onClick={this.onClickRemove}>Remove from cart</button> | |
</li> | |
); | |
} | |
render() { | |
const { items } = this.props; | |
return ( | |
<ul className='cart'> | |
{items.map((item, index) => this.renderCartItem(item, index)} | |
</ul> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment