Skip to content

Instantly share code, notes, and snippets.

@james-gardner
Forked from brigand/Enhance.js
Created November 10, 2015 14:32
Show Gist options
  • Save james-gardner/06e7a993796d1ce79849 to your computer and use it in GitHub Desktop.
Save james-gardner/06e7a993796d1ce79849 to your computer and use it in GitHub Desktop.
import { Component } from "react";
export var Enhance = ComposedComponent => class extends Component {
static displayName = "Enhanced"
constructor() {
super();
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment