inputlogic / elements

Dependable UI Components for (P)React Apps
0 stars 0 forks source link

useBreakpoint hook #151

Open coryschadt opened 4 years ago

coryschadt commented 4 years ago

Create a hook that detects screen size. Similar to this, but allow for props



export const useIsSmallDevice = () => {
  const [width, setWidth] = useState(window.innerWidth)
  const [height, setHeight] = useState(window.innerHeight)

  useEffect(() => {
    const updateSize = () => {
      setWidth(window.innerWidth)
      setHeight(window.innerHeight)
    }
    window.addEventListener("resize", updateSize)
    return () => window.removeEventListener("resize", updateSize)
  }, [])
  return width < 767 || height < 500
}