fix: responsiveness when resizing window on web/desktop (#1637)

This commit is contained in:
Aman Harwara
2022-09-24 21:24:10 +05:30
committed by GitHub
parent c2a1918843
commit e4b1b64119
8 changed files with 46 additions and 19 deletions

View File

@@ -0,0 +1,26 @@
import { useEffect, useState } from 'react'
// Follows https://tailwindcss.com/docs/responsive-design
export const MediaQueryBreakpoints = {
sm: '(min-width: 640px)',
md: '(min-width: 768px)',
lg: '(min-width: 1024px)',
xl: '(min-width: 1280px)',
'2xl': '(min-width: 1536px)',
} as const
export const useMediaQuery = (mediaQuery: string) => {
const [matches, setMatches] = useState(() => window.matchMedia(mediaQuery).matches)
useEffect(() => {
const handler = (event: MediaQueryListEvent) => {
setMatches(event.matches)
}
window.matchMedia(mediaQuery).addEventListener('change', handler)
return () => window.matchMedia(mediaQuery).removeEventListener('change', handler)
}, [mediaQuery])
return matches
}