mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:46:29 +00:00
23 lines
591 B
TypeScript
23 lines
591 B
TypeScript
import { useEffect, useState } from 'react';
|
|
|
|
const useMobileView = () => {
|
|
const [width, setWidth] = useState<number>(typeof window !== 'undefined' ? window.innerWidth : 1366);
|
|
|
|
function handleWindowSizeChange() {
|
|
setWidth(window?.innerWidth);
|
|
}
|
|
|
|
useEffect(() => {
|
|
window.addEventListener('resize', handleWindowSizeChange);
|
|
return () => {
|
|
window.removeEventListener('resize', handleWindowSizeChange);
|
|
}
|
|
}, []);
|
|
|
|
return {
|
|
isMobile: width <= 768,
|
|
windowWidth: width
|
|
};
|
|
}
|
|
|
|
export default useMobileView; |