import * as React from 'react'; export function fillRef(ref: React.Ref, node: T) { if (typeof ref === 'function') { ref(node); } else if (typeof ref === 'object' && ref && 'current' in ref) { (ref as any).current = node; } } export function composeRef(...refs: React.Ref[]): React.Ref { return (node: T) => { refs.forEach(ref => { fillRef(ref, node); }); }; } export function usePrevious(value: T): T | undefined { const ref = React.useRef(); React.useEffect(() => { ref.current = value; }, [value]); return ref.current; }