MCPcopy
hub / github.com/usememos/memos / useMediaQuery

Function useMediaQuery

web/src/hooks/useMediaQuery.ts:11–32  ·  view source on GitHub ↗
(breakpoint: Breakpoint)

Source from the content-addressed store, hash-verified

9};
10
11const useMediaQuery = (breakpoint: Breakpoint): boolean => {
12 const [matches, setMatches] = useState(() => {
13 if (typeof window === "undefined") return false;
14 return window.matchMedia(`(min-width: ${BREAKPOINTS[breakpoint]}px)`).matches;
15 });
16
17 useEffect(() => {
18 const mediaQuery = window.matchMedia(`(min-width: ${BREAKPOINTS[breakpoint]}px)`);
19
20 const handleChange = (e: MediaQueryListEvent) => {
21 setMatches(e.matches);
22 };
23
24 mediaQuery.addEventListener("change", handleChange);
25
26 return () => {
27 mediaQuery.removeEventListener("change", handleChange);
28 };
29 }, [breakpoint]);
30
31 return matches;
32};
33
34export default useMediaQuery;

Callers 8

PreviewImageDialogFunction · 0.85
MobileHeaderFunction · 0.85
RootLayoutFunction · 0.85
MainLayoutFunction · 0.85
InboxesFunction · 0.85
SettingFunction · 0.85
MemoDetailFunction · 0.85
AttachmentsFunction · 0.85

Calls 2

addEventListenerMethod · 0.80
removeEventListenerMethod · 0.80

Tested by

no test coverage detected