mirror of
https://github.com/grafana/grafana.git
synced 2024-12-02 05:29:42 -06:00
8e9ccfc66e
* ensure media queries transition properly * fix unit tests
18 lines
519 B
TypeScript
18 lines
519 B
TypeScript
import { useEffect } from 'react';
|
|
|
|
export function useMediaQueryChange({
|
|
breakpoint,
|
|
onChange,
|
|
}: {
|
|
breakpoint: number;
|
|
onChange: (e: MediaQueryListEvent) => void;
|
|
}) {
|
|
useEffect(() => {
|
|
const mediaQuery = window.matchMedia(`(min-width: ${breakpoint}px)`);
|
|
const onMediaQueryChange = (e: MediaQueryListEvent) => onChange(e);
|
|
mediaQuery.addEventListener('change', onMediaQueryChange);
|
|
|
|
return () => mediaQuery.removeEventListener('change', onMediaQueryChange);
|
|
}, [breakpoint, onChange]);
|
|
}
|