lbry-desktop/ui/effects/use-on-resize.js
2022-02-07 10:18:50 -05:00

18 lines
435 B
JavaScript

import { useEffect } from 'react';
import debounce from 'util/debounce';
export function useOnResize(cb) {
const isWindowClient = typeof window === 'object';
useEffect(() => {
const handleResize = debounce(cb, 100);
if (isWindowClient) {
window.addEventListener('resize', handleResize);
handleResize();
return () => window.removeEventListener('resize', handleResize);
}
}, [isWindowClient]);
}