Skip to content

Instantly share code, notes, and snippets.

@caike caike/hoc-demo.js
Created May 9, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.