Guest User

Untitled

a guest
Dec 10th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. constructor() {
  2. super();
  3. this.ref = firebase.firestore().collection('posts');
  4. this.firestoreUnsubscriber = null;
  5. this.authUnsubscriber = null;
  6. this.state = {
  7. posts: [],
  8. loading: true,
  9. loggingIn: false,
  10. user: null,
  11. emailValue: '',
  12. passwordValue: '',
  13. hasError: false,
  14. error: '',
  15. };
  16. }
  17.  
  18. componentDidMount() {
  19. this.authUnsubscriber = firebase.auth().onAuthStateChanged((user) => {
  20. this.setState({ user });
  21. });
  22. this.firestoreUnsubscriber = this.ref.onSnapshot(this.onCollectionUpdate)
  23. }
  24.  
  25. componentWillUnmount() {
  26. if (this.authUnsubscriber) {
  27. this.authUnsubscriber();
  28. }
  29. if (this.firestoreUnsubscriber) {
  30. this.firestoreUnsubscriber();
  31. }
  32. }
Add Comment
Please, Sign In to add comment