useLongPress Hook
In this section, I will demonstrate about the useWindowSize Hook that will be used for the detecting the Window Size
import React, { useEffect, useState } from 'react';
interface IWindow {
width: number | undefined;
height: number | undefined;
}
const useWindowSize = () => {
const [windowSize, setWindowSize] = useState<IWindow>({
width: undefined,
height: undefined,
});
useEffect(() => {
const handleResize = () => {
setWindowSize({
width: window.innerWidth,
height: window.innerHeight,
});
};
window.addEventListener('resize', handleResize);
handleResize();
return () => {
window.removeEventListener('resize', handleResize);
};
}, []);
return windowSize;
};
export default useWindowSize;
// Usage
const { width, height } = useWindowSize();