Created
February 3, 2020 22:55
-
-
Save blikblum/28bb5f005d1034ac3b773231ea05a95c to your computer and use it in GitHub Desktop.
Markdium-From React to Web Components: using hooks
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
useEffect(() => { | |
const handleNewMessages = snap => { | |
// avoid updating messages when there are no changes | |
const changes = snap.docChanges() | |
if (changes.length) { | |
setMessages(snap.docs.map(doc => doc.data())) | |
} | |
} | |
const unsubscribe = chatRoomMessages.onSnapshot(handleNewMessages); | |
return unsubscribe; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment