blob: 92bf1849fb445d031980d44136569f1bdcc5a1ff (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
import { useEffect, useState } from 'react'
const useWindowWidth = () => {
const [windowWidth, setWindowWidth] = useState()
useEffect(() => {
const handleResize = () => {
setWindowWidth(window.innerWidth)
}
window.addEventListener('resize', handleResize)
// Cleanup function to remove the event listener
return () => window.removeEventListener('resize', handleResize)
}, [])
return windowWidth
}
export default useWindowWidth
|