Context

Sometimes you may need to throw parameters into several components at once. For example, you need to provide all of your components with translations. And each time to transmit props will be simply tedious. Here you will be helped by the context.

To pass the context to the children you need to implement a method passContext in the parent component and return the context object.

Also inside the method passContext you can use objects this.props and this.state

And in the component, the expecting context is to implement a static method injectContextand return an array of properties of the expected context.

Example:

class User extends Component { static injectContext() { return ['username'] } render() { return this.context.username } } class App extends Component { passContext() { return { username: 'Igor', } } render() { return User.v() } }