<div id="root"></div>
class Parent extends React.Component {
  static childContextTypes = {
    data: PropTypes.string
  }

  getChildContext () {
    return {
      data: "data"
    }
  }

  render() {
    return (
      <Child />
    )
  }
}

class Child extends React.Component {
  static contextTypes = {
    data: PropTypes.string
  }

  render() {
    return (
      <div>Child中获取Context:{this.context.data}</div>
    )
  }
}

ReactDOM.render(<Parent />, document.getElementById("root"))
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/react/16.12.0/umd/react.production.min.js
  2. https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.11.0/umd/react-dom.production.min.js
  3. https://cdnjs.cloudflare.com/ajax/libs/prop-types/15.7.2/prop-types.min.js