2022-01-28 16:03:06 +01:00
|
|
|
import { useEffect } from 'react';
|
2022-01-28 16:42:02 +01:00
|
|
|
import debounce from 'util/debounce';
|
2022-01-28 16:03:06 +01:00
|
|
|
|
|
|
|
export function useOnResize(cb) {
|
|
|
|
useEffect(() => {
|
2022-01-28 16:42:02 +01:00
|
|
|
const handleResize = debounce(cb, 100);
|
2022-01-28 16:03:06 +01:00
|
|
|
|
|
|
|
window.addEventListener('resize', handleResize);
|
|
|
|
|
|
|
|
handleResize();
|
|
|
|
|
|
|
|
return () => window.removeEventListener('resize', handleResize);
|
2022-01-28 16:42:02 +01:00
|
|
|
}, []);
|
2022-01-28 16:03:06 +01:00
|
|
|
}
|