-
-
Save brigand/1c476f365a503d5a1e2d to your computer and use it in GitHub Desktop.
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 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} />; | |
} | |
}; |
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 { Enhance } from "./Enhance"; | |
class MyComponent { | |
render() { | |
if (!this.data) return <div>Waiting...</div>; | |
return <div>{this.data}</div>; | |
} | |
} | |
export default Enhance(MyComponent); // Enhanced component |
I cannot get HigherOrderComponent.js
to work. Shouldn't it be this.props.data
instead this.data
inside MyComponent
? Because that actually works.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes. It's just a pattern, not a feature.