MCPcopy
hub / github.com/untitleduico/react / useBreakpoint

Function useBreakpoint

hooks/use-breakpoint.ts:21–36  ·  view source on GitHub ↗
(size: "sm" | "md" | "lg" | "xl" | "2xl")

Source from the content-addressed store, hash-verified

19 * @returns A boolean indicating whether the viewport size applies.
20 */
21export const useBreakpoint = (size: "sm" | "md" | "lg" | "xl" | "2xl") => {
22 const [matches, setMatches] = useState(typeof window !== "undefined" ? window.matchMedia(`(min-width: ${screens[size]})`).matches : true);
23
24 useEffect(() => {
25 const breakpoint = window.matchMedia(`(min-width: ${screens[size]})`);
26
27 setMatches(breakpoint.matches);
28
29 const handleChange = (value: MediaQueryListEvent) => setMatches(value.matches);
30
31 breakpoint.addEventListener("change", handleChange);
32 return () => breakpoint.removeEventListener("change", handleChange);
33 }, [size]);
34
35 return matches;
36};

Callers 11

PaginationPageDefaultFunction · 0.90
PaginationCardDefaultFunction · 0.90
PaginationButtonGroupFunction · 0.90
NavAccountCardFunction · 0.90
LineChart01Function · 0.90
LineChart02Function · 0.90
LineChart03Function · 0.90
LineChart04Function · 0.90
BarChartFunction · 0.90
RangeCalendarFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected