Skip to content

Instantly share code, notes, and snippets.

@Jahans3
Last active November 29, 2018 19:40
Show Gist options
  • Save Jahans3/2ec6438dcb2df2015b7dc6e91ffedce5 to your computer and use it in GitHub Desktop.
Save Jahans3/2ec6438dcb2df2015b7dc6e91ffedce5 to your computer and use it in GitHub Desktop.
Our context's provider
import React, { Component, createContext } from 'react';
const { Provider, Consumer } = createContext();
export const StateConsumer = Consumer;
export class StateProvider extends Component {
static defaultProps = {
state: {}
};
state = this.props.state;
render () {
return (
<Provider value={this.state}>
{this.props.children}
</Provider>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment