2020-09-15 15:01:07 +02:00
|
|
|
import { useEffect } from 'react';
|
|
|
|
const debounce = require('debounce');
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
export default function useWindowResizeEvent(eventEmitter: any) {
|
2020-09-15 15:01:07 +02:00
|
|
|
useEffect(() => {
|
|
|
|
const window_resize = debounce(() => {
|
|
|
|
eventEmitter.current.emit('resize');
|
|
|
|
}, 500);
|
|
|
|
|
|
|
|
window.addEventListener('resize', window_resize);
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
window_resize.clear();
|
|
|
|
window.removeEventListener('resize', window_resize);
|
|
|
|
};
|
2022-08-19 13:10:04 +02:00
|
|
|
// eslint-disable-next-line @seiyab/react-hooks/exhaustive-deps -- Old code before rule was applied
|
2020-09-15 15:01:07 +02:00
|
|
|
}, []);
|
|
|
|
}
|