Skip to content

Instantly share code, notes, and snippets.

@dskecse
Forked from sebmarkbage/Enhance.js
Last active May 28, 2016 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dskecse/541d90e623afeba744fa51ef3b949b54 to your computer and use it in GitHub Desktop.
Save dskecse/541d90e623afeba744fa51ef3b949b54 to your computer and use it in GitHub Desktop.
Higher-order Components
import { Component } from "React";
export const Enhance = ComposedComponent => class extends Component {
constructor() {
super()
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
return <ComposedComponent {...this.props} data={this.state.data} />;
}
};
import { Enhance } from "./Enhance";
const MyComponent = props => (
if (!props.data) return <div>Waiting...</div>;
return <div>{props.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