Skip to content

Instantly share code, notes, and snippets.

@d6u
Created December 22, 2015 21:53
Show Gist options
  • Select an option

  • Save d6u/830767507ef014f4f4d2 to your computer and use it in GitHub Desktop.

Select an option

Save d6u/830767507ef014f4f4d2 to your computer and use it in GitHub Desktop.
Apply className with Higher Order Component
import { Component } from 'React';
class MyComponent extends Component {
render() {
return (
<div className='container'><div className='box'>the box</div></div>
);
}
}
export var Enhance = ComposedComponent => class extends Component {
render() {
// How can I apply 'some_class_name' to .container in ComposedComponent
// without ComposedComponent knowing what to do?
return <ComposedComponent className='some_class_name' />;
}
};
const NewComponent = Enhance(MyComponent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment