diff --git a/src/util/index.ts b/src/util/index.ts index 44169cc..b49f152 100644 --- a/src/util/index.ts +++ b/src/util/index.ts @@ -3,6 +3,20 @@ import useLocation from "wouter/use-location"; export const sleep = (t: number) => new Promise(r => setTimeout(r, t)); +type Ref = + | React.MutableRefObject + | React.RefCallback + | React.ForwardedRef; + +export const composeRefs = (...refs: Ref[]) => { + return (el: T) => { + refs.forEach(ref => { + if (typeof ref === "function") ref(el); + else if (ref) ref.current = el; + }); + }; +}; + export function* intersperse( xs: T[], delim: (index: number) => U, @@ -21,7 +35,7 @@ export function* intersperse( } export const getTimeout = () => { - const clearables = new Set(); + const clearables = new Set>(); const timeout = (f: (...attr: any[]) => any, t: number) => { const self = setTimeout(() => (f(), clearables.delete(self)), t);