Skip to content

Instantly share code, notes, and snippets.

@sbatson5
Created January 6, 2022 16:00
Show Gist options
  • Save sbatson5/a1795434263ddc6728938b0fc0471953 to your computer and use it in GitHub Desktop.
Save sbatson5/a1795434263ddc6728938b0fc0471953 to your computer and use it in GitHub Desktop.
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