Skip to content

Instantly share code, notes, and snippets.

@fcsonline
Created December 2, 2016 11:45
Show Gist options
  • Save fcsonline/ce2f8e6dfb81c48c4c8b62807dcc6c6f to your computer and use it in GitHub Desktop.
Save fcsonline/ce2f8e6dfb81c48c4c8b62807dcc6c6f to your computer and use it in GitHub Desktop.
Cart - SelectableList
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