Last active
July 8, 2017 07:11
-
-
Save dtinth/8aa9680f19c2755dccfd88aeb36143d2 to your computer and use it in GitHub Desktop.
This file contains 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
export class FirebaseAuth extends React.Component { | |
static propTypes = { | |
children: PropTypes.func.isRequired | |
} | |
auth = firebase.auth() | |
state = { user: this.auth.currentUser } | |
componentDidMount () { | |
this.unsubscribe = this.auth.onAuthStateChanged(user => { | |
this.setState({ user }) | |
}) | |
} | |
componentWillUnmount () { | |
this.unsubscribe() | |
} | |
render () { | |
return this.props.children(this.state.user) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment