Created
December 2, 2016 11:45
-
-
Save fcsonline/ce2f8e6dfb81c48c4c8b62807dcc6c6f to your computer and use it in GitHub Desktop.
Cart - SelectableList
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 SelectableList extends React.Component { | |
onClickItem(event, index) { | |
this.state.setState({ | |
selected: [ | |
...this.state.selected, | |
index | |
] | |
}); | |
} | |
render() { | |
return ( | |
<ul> | |
{items.map((item, index) => { | |
const isSelected = this.state.selected.indexOf(index) >= 0 ? 'selected' : ''; | |
return ( | |
<li key={index} className={isSelected} onClick={(event) => this.onClickItem(event, index)}> | |
{renderItem(item)} | |
</li> | |
); | |
})} | |
</ul> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment