Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- constructor() {
- super();
- this.ref = firebase.firestore().collection('posts');
- this.firestoreUnsubscriber = null;
- this.authUnsubscriber = null;
- this.state = {
- posts: [],
- loading: true,
- loggingIn: false,
- user: null,
- emailValue: '',
- passwordValue: '',
- hasError: false,
- error: '',
- };
- }
- componentDidMount() {
- this.authUnsubscriber = firebase.auth().onAuthStateChanged((user) => {
- this.setState({ user });
- });
- this.firestoreUnsubscriber = this.ref.onSnapshot(this.onCollectionUpdate)
- }
- componentWillUnmount() {
- if (this.authUnsubscriber) {
- this.authUnsubscriber();
- }
- if (this.firestoreUnsubscriber) {
- this.firestoreUnsubscriber();
- }
- }
Add Comment
Please, Sign In to add comment