Skip to content

Instantly share code, notes, and snippets.

@caike
Created May 9, 2019 12:31
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 caike/f2f46b8e1d6731b0d83af56b3a5947c3 to your computer and use it in GitHub Desktop.
Save caike/f2f46b8e1d6731b0d83af56b3a5947c3 to your computer and use it in GitHub Desktop.
Higher Order Component demo
function App(props){
return `Message ${props.classes.button} ${props.classes.isActive}`;
}
const styles = {
button: "btn-primary",
isActive: "is-active"
};
const styledProps = withStyles(styles);
console.log( styledProps(App) );
function withStyles(obj){
const props = { classes: {} };
Object.keys(obj).forEach(k => {
props.classes[k] = obj[k];
});
return function(app){
return app(props);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment