Skip to content

Instantly share code, notes, and snippets.

@viceversus
Last active January 30, 2016 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viceversus/c4ba0d824655a05b9af7 to your computer and use it in GitHub Desktop.
Save viceversus/c4ba0d824655a05b9af7 to your computer and use it in GitHub Desktop.
List Wrapper Higher Order Component
function listWrapper(ListComponent) {
const ListWrapper = React.createClass({
getInitialState() {
return {
selection: new Set(),
};
},
handleOnSelect(item) {
if(this.state.selection.has(item)) {
this.state.selection.delete(item);
} else {
this.state.selection.add(item);
}
},
render() {
return (<ListComponent
onSelect={this.handleOnSelect}
{...this.props}
{...this.state}
/>
);
},
});
return ListWrapper;
}
export default listWrapper;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment