MCPcopy
hub / github.com/danielpetho/fancy / useScreenSize

Function useScreenSize

src/hooks/use-screen-size.ts:52–80  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

50}
51
52const useScreenSize = (): ComparableScreenSize => {
53 const [screenSize, setScreenSize] = useState<ScreenSize>("xs")
54
55 useEffect(() => {
56 const handleResize = () => {
57 const width = window.innerWidth
58
59 if (width >= 1536) {
60 setScreenSize("2xl")
61 } else if (width >= 1280) {
62 setScreenSize("xl")
63 } else if (width >= 1024) {
64 setScreenSize("lg")
65 } else if (width >= 768) {
66 setScreenSize("md")
67 } else if (width >= 640) {
68 setScreenSize("sm")
69 } else {
70 setScreenSize("xs")
71 }
72 }
73
74 handleResize()
75 window.addEventListener("resize", handleResize)
76 return () => window.removeEventListener("resize", handleResize)
77 }, [])
78
79 return new ComparableScreenSize(screenSize)
80}
81
82export default useScreenSize

Callers 15

BoxCarouselDemoFunction · 0.85
BoxCarouselDemoFunction · 0.85
BoxCarouselDemoFunction · 0.85
PreviewFunction · 0.85
PreviewFunction · 0.85
DragElementsDemoFunction · 0.85
CirclingElementsDemoFunction · 0.85
CirclingElementsDemoFunction · 0.85
PreviewFunction · 0.85
PreviewFunction · 0.85
CSSBoxScrollDemoFunction · 0.85

Calls 1

handleResizeFunction · 0.85

Tested by

no test coverage detected