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;