Refactor useWindowWidth hook to improve readability
This commit is contained in:
@@ -1,19 +1,14 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
const useWindowWidth = () => {
|
||||
const [windowWidth, setWindowWidth] = useState()
|
||||
function useWindowWidth() {
|
||||
const [width, setWidth] = useState(window.innerWidth)
|
||||
|
||||
useEffect(() => {
|
||||
const handleResize = () => {
|
||||
setWindowWidth(window.innerWidth)
|
||||
}
|
||||
|
||||
const handleResize = () => setWidth(window.innerWidth)
|
||||
window.addEventListener('resize', handleResize)
|
||||
|
||||
// Cleanup function to remove the event listener
|
||||
return () => window.removeEventListener('resize', handleResize)
|
||||
}, [])
|
||||
|
||||
return windowWidth
|
||||
return width
|
||||
}
|
||||
|
||||
export default useWindowWidth
|
||||
|
||||
Reference in New Issue
Block a user