mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 20:19:49 +02:00
feat: reactive wide format
This commit is contained in:
1 parent
0b12f65949
commit
af4d2dbfd0
1 file changed
+16
-1
@@ -1,4 +1,19 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
function hasWideFormat() {
|
||||||
|
return typeof window !== 'undefined' && window.innerWidth > 880;
|
||||||
|
}
|
||||||
|
|
||||||
export function useWideFormat() {
|
export function useWideFormat() {
|
||||||
const wideFormat = typeof window !== 'undefined' && window.innerWidth > 880;
|
const [wideFormat, setWideFormat] = useState(hasWideFormat());
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
function handleResize() {
|
||||||
|
setWideFormat(hasWideFormat());
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('resize', handleResize);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return wideFormat;
|
return wideFormat;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user