Skip to content

Instantly share code, notes, and snippets.

@LeezQ
Forked from sebmarkbage/Enhance.js
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save LeezQ/8487a8c3646f139017f1 to your computer and use it in GitHub Desktop.

Select an option

Save LeezQ/8487a8c3646f139017f1 to your computer and use it in GitHub Desktop.
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
return <ComposedComponent {...this.props} data={this.state.data} />;
}
};
import { Enhance } from "./Enhance";
class MyComponent {
render() {
if (!this.data) return <div>Waiting...</div>;
return <div>{this.data}</div>;
}
}
export default Enhance(MyComponent); // Enhanced component
@LeezQ

LeezQ commented Apr 30, 2015

Copy link
Copy Markdown
Author

high order component

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment