mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-01-23 19:27:04 +00:00
19 lines
498 B
TypeScript
19 lines
498 B
TypeScript
import { useState, useEffect } from 'react';
|
|
|
|
const useViewport = (threshold = 1024) => {
|
|
const [isSmallViewport, setIsSmallViewport] = useState(window.innerWidth < threshold);
|
|
|
|
useEffect(() => {
|
|
const handleResize = () => setIsSmallViewport(window.innerWidth < threshold);
|
|
window.addEventListener('resize', handleResize);
|
|
|
|
return () => {
|
|
window.removeEventListener('resize', handleResize);
|
|
};
|
|
}, [threshold]);
|
|
|
|
return isSmallViewport;
|
|
};
|
|
|
|
export default useViewport;
|