Last active
January 30, 2016 01:32
-
-
Save viceversus/c4ba0d824655a05b9af7 to your computer and use it in GitHub Desktop.
List Wrapper Higher Order Component
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
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