Stop checking for window in useEffect
This commit is contained in:
parent
6cefb12f30
commit
3c04ca840f
@ -4,18 +4,16 @@ export default function useIsDesktop() {
|
||||
const [isDesktop, setIsDesktop] = useState<boolean>();
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window !== 'undefined') {
|
||||
const breakpointMd = getComputedStyle(document.body)
|
||||
.getPropertyValue('--breakpoint-md');
|
||||
const mql = window.matchMedia(`(min-width: ${breakpointMd})`);
|
||||
setIsDesktop(mql.matches);
|
||||
const breakpointMd = getComputedStyle(document.body)
|
||||
.getPropertyValue('--breakpoint-md');
|
||||
const mql = window.matchMedia(`(min-width: ${breakpointMd})`);
|
||||
setIsDesktop(mql.matches);
|
||||
|
||||
const eventHandler = (event: MediaQueryListEvent) =>
|
||||
setIsDesktop(event.matches);
|
||||
const eventHandler = (event: MediaQueryListEvent) =>
|
||||
setIsDesktop(event.matches);
|
||||
|
||||
mql.addEventListener('change', eventHandler);
|
||||
return () => mql.removeEventListener('change', eventHandler);
|
||||
}
|
||||
mql.addEventListener('change', eventHandler);
|
||||
return () => mql.removeEventListener('change', eventHandler);
|
||||
}, []);
|
||||
|
||||
return isDesktop;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user