mirror of
https://codeberg.org/MarkusThielker/finances.git
synced 2025-04-12 05:08:43 +00:00
21 lines
588 B
TypeScript
21 lines
588 B
TypeScript
'use client';
|
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
export function useMediaQuery(mq: string) {
|
|
|
|
const [matches, setMatch] = useState(
|
|
() => typeof window !== 'undefined' ? window.matchMedia(mq).matches : false,
|
|
);
|
|
|
|
useEffect(() => {
|
|
if (typeof window !== 'undefined') {
|
|
const mql = window.matchMedia(mq);
|
|
const listener = (e: any) => setMatch(e.matches);
|
|
mql.addEventListener('change', listener);
|
|
return () => mql.removeEventListener('change', listener);
|
|
}
|
|
}, [mq]);
|
|
|
|
return matches;
|
|
}
|