Skip to content

Instantly share code, notes, and snippets.

@fiqryq
Created April 7, 2022 13:18
Show Gist options
  • Save fiqryq/cf166598baefc189cf399b868b1f57fe to your computer and use it in GitHub Desktop.
Save fiqryq/cf166598baefc189cf399b868b1f57fe to your computer and use it in GitHub Desktop.
width canvas listener custom hooks
import React from 'react'
export const useWindows = () => {
const [size, setSize] = React.useState([window.innerWidth])
React.useEffect(() => {
const handleResize = () => {
setSize([window.innerWidth])
}
window.addEventListener('resize', handleResize)
return () => {
window.addEventListener('resize', handleResize)
}
}, [])
return size
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment