From 8b5fee3dfd2ab3e99d90e2c264229042135ac614 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Wed, 10 Apr 2024 17:31:26 +0800 Subject: [PATCH] Just sub it once --- src/pages/notifications.jsx | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/pages/notifications.jsx b/src/pages/notifications.jsx index 84c581f..db70d26 100644 --- a/src/pages/notifications.jsx +++ b/src/pages/notifications.jsx @@ -247,7 +247,6 @@ function Notifications({ columnMode }) { const lastHiddenTime = useRef(); usePageVisibility((visible) => { - let unsub; if (visible) { const timeDiff = Date.now() - lastHiddenTime.current; if (!lastHiddenTime.current || timeDiff > 1000 * 3) { @@ -258,20 +257,16 @@ function Notifications({ columnMode }) { } else { lastHiddenTime.current = Date.now(); } - unsub = subscribeKey(states, 'notificationsShowNew', (v) => { - if (uiState === 'loading') { - return; - } - if (v) { - loadUpdates(); - } - setShowNew(v); - }); } - return () => { - unsub?.(); - }; }); + useEffect(() => { + let unsub = subscribeKey(states, 'notificationsShowNew', (v) => { + if (uiState === 'loading') return; + if (v) loadUpdates(); + setShowNew(v); + }); + return () => unsub?.(); + }, []); const todayDate = new Date(); const yesterdayDate = new Date(todayDate - 24 * 60 * 60 * 1000);