INIT
This commit is contained in:
17
frontend/src/hooks/use-media-query.ts
Normal file
17
frontend/src/hooks/use-media-query.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import * as React from "react"
|
||||
|
||||
export function useMediaQuery(query: string) {
|
||||
const [matches, setMatches] = React.useState<boolean>(false)
|
||||
|
||||
React.useEffect(() => {
|
||||
const mql = window.matchMedia(query)
|
||||
const onChange = () => {
|
||||
setMatches(mql.matches)
|
||||
}
|
||||
mql.addEventListener("change", onChange)
|
||||
setMatches(mql.matches)
|
||||
return () => mql.removeEventListener("change", onChange)
|
||||
}, [query])
|
||||
|
||||
return matches
|
||||
}
|
||||
Reference in New Issue
Block a user