mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 02:10:15 +01:00
18 lines
502 B
TypeScript
18 lines
502 B
TypeScript
|
|
import { useEffect, useState } from 'react';
|
||
|
|
|
||
|
|
export default function useMediaQuery(query: string) {
|
||
|
|
const [matches, setMatches] = useState(false);
|
||
|
|
|
||
|
|
useEffect(() => {
|
||
|
|
const media = window.matchMedia(query);
|
||
|
|
if (media.matches !== matches) {
|
||
|
|
setMatches(media.matches);
|
||
|
|
}
|
||
|
|
const listener = () => setMatches(media.matches);
|
||
|
|
media.addEventListener('change', listener);
|
||
|
|
return () => media.removeEventListener('change', listener);
|
||
|
|
}, [matches, query]);
|
||
|
|
|
||
|
|
return matches;
|
||
|
|
}
|