Skip to content

Instantly share code, notes, and snippets.

@jamsesso
Last active July 10, 2016 16:42
Show Gist options
  • Save jamsesso/a3a27fd6250c7c739fc1b1ec291c3c1a to your computer and use it in GitHub Desktop.
Save jamsesso/a3a27fd6250c7c739fc1b1ec291c3c1a to your computer and use it in GitHub Desktop.
import React, { Component, PropTypes } from 'react'
import { render } from 'react-dom'
class Parent extends Component {
static childContextTypes = {
someContext1: PropTypes.object,
someContext2: PropTypes.object
}
render() {
return (
<Stuff>
{this.props.children}
</Stuff>
)
}
}
class Child extends Component {
static contextTypes = {
someContext1: PropTypes.object.isRequired,
someContext2: PropTypes.object.isRequired
}
render() {
console.log('Context:', this.context)
// -> Object { someContext1: {...}, someContext2: {...} }
console.log('Props:', this.props)
// -> Object { } (usually some stuff, but we don't care right now)
}
}
render(
<Parent>
<Child />
</Parent>,
document.getElementById('root')
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment