serpbear/hooks/useWindowResize.tsx
towfiqi 4a47cedad8 refactor: improves Performance & Code Readability
- Replaces useEffet with useMemo & useLayoutEffect where necessary.
- Converts some useEffects to separate hooks.
- Moves the functions defined within components to utils.
- Splits the Keywords renderPosition function to its own component.
2024-01-13 10:10:49 +06:00

14 lines
321 B
TypeScript

import { useEffect } from 'react';
const useWindowResize = (onResize: () => void) => {
useEffect(() => {
onResize();
window.addEventListener('resize', onResize);
return () => {
window.removeEventListener('resize', onResize);
};
}, [onResize]);
};
export default useWindowResize;