Skip to content

Instantly share code, notes, and snippets.

@gigobyte
Created May 15, 2017 19:26
Show Gist options
  • Save gigobyte/f0de8ffd9a4dcf4c11bedfe4bd8185d1 to your computer and use it in GitHub Desktop.
Save gigobyte/f0de8ffd9a4dcf4c11bedfe4bd8185d1 to your computer and use it in GitHub Desktop.
const styleable = (ParentComponent) => class extends ParentComponent {
static displayName = `Styleable(${ParentComponent.displayName || ParentComponent.name})`
render() {
const originalElement = super.render()
const className = `${originalElement.props.className} ${this.props.className}`
const style = {...originalElement.props.style, ...this.props.style}
const newProps = {...originalElement.props, className, style}
return React.cloneElement(originalElement, newProps)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment