-
-
Save jeromepl/2f7df563f273563261690221c22aa0af to your computer and use it in GitHub Desktop.
Higher-order Components in React with ES7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from "React"; | |
export default (ComposedComponent) => class extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { data: null }; | |
} | |
componentDidMount() { | |
this.setState({ data: 'Hello' }); | |
} | |
render() { | |
return <ComposedComponent {...this.props} data={this.state.data} />; | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from "React"; | |
import enhance from "./Enhance"; | |
@enhance | |
export default class MyComponent extends Component { | |
render() { | |
if (!this.props.data) return <div>Waiting...</div>; | |
return <div>{this.props.data}</div>; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment