Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. constructor() {
  2.     super();
  3.     this.unsubscribe = null;
  4.     this.ref = firebase.firestore().collection("termins");
  5.   }
  6.   state = {
  7.     snapshots: [],
  8.     loading: true
  9.   };
  10. componentDidMount() {
  11.     this.unsubscribe = this.ref.onSnapshot(this.onCollectionUpdate)
  12. }
  13.  
  14. componentWillUnmount() {
  15.     this.unsubscribe();
  16. }
  17. onCollectionUpdate = (querySnapshot) => {
  18.   const todos = [];
  19.   querySnapshot.forEach((doc) => {
  20.     const { time, salonname } = doc.data();
  21.    
  22.     todos.push({
  23.       key: doc.id,
  24.       doc, // DocumentSnapshot
  25.       time,
  26.       salonname,
  27.     });
  28.   });
  29.  
  30.   this.setState({
  31.     todos,
  32.     loading: false,
  33.  });
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement