refactor(frontend):remove unnecessary hook abstraction

This commit is contained in:
Alex Kaminskii 2022-11-25 23:18:22 +01:00
parent 81cdd7b91d
commit 76b78150ef
2 changed files with 8 additions and 27 deletions

View file

@ -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

View file

@ -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;