mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-14 15:00:54 -05:00
26 lines
650 B
TypeScript
26 lines
650 B
TypeScript
import { useState, useEffect } from "react"
|
|
|
|
function getWindowWidth() {
|
|
const { innerWidth: width } = window
|
|
return width
|
|
}
|
|
|
|
export default function useBreakPoints(breakpoints: number | number[]) {
|
|
const [windowWidth, setWindowWidth] = useState<number>(getWindowWidth())
|
|
|
|
useEffect(() => {
|
|
function handleResize() {
|
|
setWindowWidth(getWindowWidth())
|
|
}
|
|
|
|
window.addEventListener("resize", handleResize)
|
|
return () => window.removeEventListener("resize", handleResize)
|
|
}, [])
|
|
|
|
if (Array.isArray(breakpoints)) {
|
|
return breakpoints.map(breakpoint => windowWidth < breakpoint)
|
|
}
|
|
|
|
return windowWidth < breakpoints
|
|
}
|