Last active
May 14, 2019 16:55
-
-
Save samcorcos/fba8cc670180ed171a04f38eb171f70e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react' | |
| import { firebase } from './firebase' | |
| export const initialState = { | |
| currentUser: {}, | |
| data: {} | |
| } | |
| export const Context = React.createContext(initialState) | |
| /** | |
| * This component is the Context Provider using the new React Context API that | |
| * gives the app store state | |
| * https://blog.bitsrc.io/react-context-api-a-replacement-for-redux-6e20790492b3 | |
| */ | |
| export class Provider extends React.Component { | |
| state = initialState | |
| signOut = async () => { | |
| await firebase.auth().signOut() | |
| this.setState({ ...initialState }) | |
| } | |
| set = (key, value) => { | |
| this.setState({ [key]: value }) | |
| } | |
| render () { | |
| return ( | |
| <Context.Provider | |
| value={{ | |
| // NOTE any actions defined in this component must be added to the value here as well | |
| ...this.state, | |
| set: this.set, | |
| signOut: this.signOut | |
| }}> | |
| {this.props.children} | |
| </Context.Provider> | |
| ) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment