Add hover cards in web UI (#30754)
Co-authored-by: Renaud Chaput <renchap@gmail.com>
This commit is contained in:
parent
863c470a2b
commit
e89317d4c1
18 changed files with 631 additions and 42 deletions
29
app/javascript/hooks/useTimeout.ts
Normal file
29
app/javascript/hooks/useTimeout.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import { useRef, useCallback, useEffect } from 'react';
|
||||
|
||||
export const useTimeout = () => {
|
||||
const timeoutRef = useRef<ReturnType<typeof setTimeout>>();
|
||||
|
||||
const set = useCallback((callback: () => void, delay: number) => {
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current);
|
||||
}
|
||||
|
||||
timeoutRef.current = setTimeout(callback, delay);
|
||||
}, []);
|
||||
|
||||
const cancel = useCallback(() => {
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current);
|
||||
timeoutRef.current = undefined;
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
cancel();
|
||||
},
|
||||
[cancel],
|
||||
);
|
||||
|
||||
return [set, cancel] as const;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue