aboutsummaryrefslogtreecommitdiffstats
path: root/src/hooks/useWindowWidth.js
blob: fa79cc429fcb0b008138f112cdc28f9d48ffc955 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { useEffect, useState } from 'react'
function useWindowWidth() {
  const [width, setWidth] = useState(window.innerWidth)

  useEffect(() => {
    const handleResize = () => setWidth(window.innerWidth)
    window.addEventListener('resize', handleResize)
    return () => window.removeEventListener('resize', handleResize)
  }, [])

  return width
}

export default useWindowWidth