Created
January 6, 2022 16:00
-
-
Save sbatson5/a1795434263ddc6728938b0fc0471953 to your computer and use it in GitHub Desktop.
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
const getComments = () => { | |
return onSnapshot(collection(db, 'comments'), (value) => { | |
const comments = value.docs.reduce((acc, item) => { | |
if (id.id === item.data().coinId) { | |
acc.push({ ...item.data(), id: item.id }) | |
} | |
return acc; | |
}, []) | |
setComments(comments); | |
}); | |
}; | |
useEffect(() => { | |
if (!toggle) { | |
return; | |
} | |
const unsub = getComments(); | |
return unsub; | |
}, [toggle]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment