Created
July 19, 2015 18:33
-
-
Save thmain/2a0b10b548600971ff33 to your computer and use it in GitHub Desktop.
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
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