Created
February 20, 2017 15:25
-
-
Save diegocasmo/357f8463bd4b217a2a7443326f3e0942 to your computer and use it in GitHub Desktop.
The App component is the top level component of the application and all other components are wrapped by it.
This file contains hidden or 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
class App extends React.Component { | |
// Encapsulate 'appData' context as props for all children | |
renderChildrenWithContextAsProps() { | |
return React.Children.map(this.props.children, (child) => { | |
return React.cloneElement(child, { | |
appData: this.context.appData | |
}); | |
}); | |
}; | |
render() { | |
return ( | |
<div> | |
{this.renderChildrenWithContextAsProps()} | |
</div> | |
); | |
} | |
} | |
App.contextTypes = { | |
appData: React.PropTypes.object.isRequired | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment