Created
May 9, 2019 12:31
-
-
Save caike/f2f46b8e1d6731b0d83af56b3a5947c3 to your computer and use it in GitHub Desktop.
Higher Order Component demo
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 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