Last active
March 24, 2020 13:42
-
-
Save parvezmrobin/4cfdb63c2a094bebfba1e13ec0539a59 to your computer and use it in GitHub Desktop.
Revisions
-
parvezmrobin revised this gist
Mar 24, 2020 . 1 changed file with 7 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -15,16 +15,16 @@ const ChatContextProvider = (props) => { //Method to fetch chat list from Firebase const getChatList= () => { if('chats' in localStorage) { const chats = JSON.parse(localStorage.getItem('chats')); setChatList([chats]); } chatRef .doc('JyNeS95OnZ3qLDno3EVd') .onSnapshot((querySnapshot) => { setChatList([querySnapshot.data().c]); localStorage.setItem('chats', JSON.stringify(querySnapshot.data().c)); }); } -
DimaMirana created this gist
Mar 24, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ import React, {createContext, useState} from 'react'; import firebase from '../firebase'; export const ChatContext = createContext(); const ChatContextProvider = (props) => { //Firebase settings const DB = firebase.firestore(); const chatRef = DB.collection("chats"); //States const [chatList, setChatList] = useState([]); //console.log(chatList); //Method to fetch chat list from Firebase const getChatList= () => { let chatListCopy = []; chatRef .doc('JyNeS95OnZ3qLDno3EVd') .onSnapshot((querySnapshot) => { chatListCopy.push(querySnapshot.data().c); //console.log(chatListCopy); setChatList(chatListCopy); chatListCopy = []; }); } return ( <ChatContext.Provider value={{chatList, getChatList}}> {props.children} </ChatContext.Provider> ); } export default ChatContextProvider;