Last active
December 5, 2017 13:03
-
-
Save chebotiuk/fb1cea75f50104608f7e57c8a170c575 to your computer and use it in GitHub Desktop.
React HOC
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
let DebugComponent = ComponentToDebug => class ComponentNamedDebug extends Component { | |
render() { | |
return ( | |
<div className="debug"> | |
<ComponentToDebug {...this.props}/> | |
</div> | |
) | |
} | |
} |
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
const LayoutHoC = (Component) => { | |
const Layout = props => ( | |
<div className="app"> | |
<header> | |
<h1>Header goes here</h1> | |
</header> | |
<main> | |
<Component {...props} /> | |
</main> | |
</div> | |
) | |
return Layout | |
} | |
//above component can be simplified omitting extra () around parameters and using implicit return | |
let DebugComponent = ComponentToDebug => ( | |
props => ( | |
<div className="debug"> | |
<ComponentToDebug {...props}/> | |
</div> | |
) | |
); | |
//or even further omitting extra () | |
let DebugComponent = ComponentToDebug => props => ( | |
<div className="debug"> | |
<ComponentToDebug {...props}/> | |
</div> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment