React parent base context

by koba04

HTML

<script src="http://react.zpao.com/builds/master/latest/react-with-addons.js"></script>
<script src="http://react.zpao.com/builds/master/latest/JSXTransformer.js"></script>
<script src="http://facebook.github.io/react/js/jsfiddle-integration.js"></script>
<div id="app"></div>

JavaScript 1.7

class Child extends React.Component {
    static get contextTypes() {
        return {name: React.PropTypes.string};
    }
    render() {
        return <div>context: {this.context.name}</div>;
    }
}

var child = <Child />;

class Parent extends React.Component {
    static get childContextTypes() {
        return {name: React.PropTypes.string};
    }
    getChildContext() {
        return {name: 'parent'}
    }
    render() {
        return <div>{child}</div>;
    }
}


React.render(<Parent />, document.getElementById('app'));