Skip to content

Instantly share code, notes, and snippets.

@thmain
Created July 19, 2015 18:33
Show Gist options
  • Save thmain/2a0b10b548600971ff33 to your computer and use it in GitHub Desktop.
Save thmain/2a0b10b548600971ff33 to your computer and use it in GitHub Desktop.
var Grandparent = React.createClass({
childContextTypes: {
message: React.PropTypes.string.isRequired
},
getChildContext: function() {
return { message: "From Grandparent" };
},
render: function() {
return <Parent />;
}
});
var Parent = React.createClass({
// Notice how this component does not have either the
// getChildContext method or the childContextTypes map.
render: function() {
return <Child />;
}
});
var Child = React.createClass({
contextTypes: {
message: React.PropTypes.string.isRequired
},
render: function() {
return <div>message: {this.context.message}</div>;
}
});
// Outputs: "message: From Grandparent"
React.render(<Grandparent />, document.body);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment