mirror of
https://github.com/walkxcode/dashboard-icons.git
synced 2025-11-08 20:48:57 +01:00
feat(website): enhance website
This commit is contained in:
committed by
Thomas Camlong
parent
6e3a39a4cf
commit
63349f7490
25
web/src/hooks/use-media-query.ts
Normal file
25
web/src/hooks/use-media-query.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
"use client"
|
||||
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
export function useMediaQuery(query: string): boolean {
|
||||
const [matches, setMatches] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
const media = window.matchMedia(query)
|
||||
|
||||
// Initial check
|
||||
if (media.matches !== matches) {
|
||||
setMatches(media.matches)
|
||||
}
|
||||
|
||||
// Setup listener for changes
|
||||
const listener = () => setMatches(media.matches)
|
||||
media.addEventListener("change", listener)
|
||||
|
||||
// Cleanup
|
||||
return () => media.removeEventListener("change", listener)
|
||||
}, [query, matches])
|
||||
|
||||
return matches
|
||||
}
|
||||
Reference in New Issue
Block a user