From 76b78150ef43da132c91c676f86cdfa9855a97af Mon Sep 17 00:00:00 2001 From: Alex Kaminskii Date: Fri, 25 Nov 2022 23:18:22 +0100 Subject: [PATCH] refactor(frontend):remove unnecessary hook abstraction --- .../components/SessionList/SessionList.tsx | 14 +++++++------ frontend/app/hooks/useTimeout.ts | 21 ------------------- 2 files changed, 8 insertions(+), 27 deletions(-) delete mode 100644 frontend/app/hooks/useTimeout.ts diff --git a/frontend/app/components/shared/SessionListContainer/components/SessionList/SessionList.tsx b/frontend/app/components/shared/SessionListContainer/components/SessionList/SessionList.tsx index 97c02d4ca..5f279c394 100644 --- a/frontend/app/components/shared/SessionListContainer/components/SessionList/SessionList.tsx +++ b/frontend/app/components/shared/SessionListContainer/components/SessionList/SessionList.tsx @@ -11,7 +11,6 @@ import { setScrollPosition, checkForLatestSessions, } from 'Duck/search'; -import useTimeout from 'App/hooks/useTimeout'; import { numberWithCommas } from 'App/utils'; import { fetchListActive as fetchMetadata } from 'Duck/customField'; @@ -82,11 +81,14 @@ function SessionList(props: Props) { }; }, [isBookmark, isVault, activeTab]); - useTimeout(() => { - if (!document.hidden) { - props.checkForLatestSessions(); - } - }, AUTOREFRESH_INTERVAL); + useEffect(() => { + const id = setInterval(() => { + if (!document.hidden) { + props.checkForLatestSessions() + } + }, AUTOREFRESH_INTERVAL) + return () => clearInterval(id) + }, []) useEffect(() => { // handle scroll position diff --git a/frontend/app/hooks/useTimeout.ts b/frontend/app/hooks/useTimeout.ts deleted file mode 100644 index ea6dd2ba3..000000000 --- a/frontend/app/hooks/useTimeout.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { useRef, useEffect } from 'react'; - -const useTimeout = (callback: () => void, delay: number) => { - const savedCallback = useRef<() => void>(); - - useEffect(() => { - savedCallback.current = callback; - }, [callback]); - - useEffect(() => { - function tick() { - savedCallback.current && savedCallback.current(); - } - if (delay !== null) { - const id = setInterval(tick, delay); - return () => clearInterval(id); - } - }, [delay]); -}; - -export default useTimeout;