Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Commit

Permalink
#51 - Added Unsubscribe in UseEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
martinsenecal committed Mar 28, 2022
1 parent 4fd95ae commit 230561b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/components/dashboard/AdminDashboard/AdminDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function AdminDashboard() {
};

useEffect(() => {
usersRef.onSnapshot(async (snapshot) => {
const unsubscribe = usersRef.onSnapshot(async (snapshot) => {
let tableData = new Array<UnassignedPatientTableData>();
snapshot.forEach((childSnapshot) => {
const user = childSnapshot.data();
Expand All @@ -86,6 +86,10 @@ function AdminDashboard() {
setNbUnassignedPatients(tableData.length);
});

return () => {
unsubscribe();
};

// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down
5 changes: 4 additions & 1 deletion src/components/layout/NotificationsMenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ function NotificationsMenuItem() {
};

useEffect(() => {
onSnapshot(doc(firestore, 'users', `${state.id}`), (docu) => {
const unsubscribe = onSnapshot(doc(firestore, 'users', `${state.id}`), (docu) => {
const data = docu.data();
if (data && data.notifications) {
setNotifications(data.notifications);
}
});
return () => {
unsubscribe();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down

0 comments on commit 230561b

Please sign in to comment.