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