Skip to content

Instantly share code, notes, and snippets.

@shalkam
Created April 7, 2017 13:13
Show Gist options
  • Save shalkam/8604f256201652a24987b9af454a29fe to your computer and use it in GitHub Desktop.
Save shalkam/8604f256201652a24987b9af454a29fe to your computer and use it in GitHub Desktop.
Simple react context example
class Parent extends Component {
getChildContext() {
return {componentID: "123456"};
}
render() {
return <Child1 />
}
}
Parent.childContextTypes = {
componentID: React.PropTypes.string
};
class Child1 extends Component {
render() {
return <Child2 />
}
}
class Child2 extends Component {
render() {
return <div>{this.context.componentID}</div>
}
}
Child2.contextTypes = {
componentID: React.PropTypes.string
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment