refactor(frontend):remove unnecessary hook abstraction
This commit is contained in:
parent
81cdd7b91d
commit
76b78150ef
2 changed files with 8 additions and 27 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
Loading…
Add table
Reference in a new issue