aboutsummaryrefslogtreecommitdiffstats
path: root/src/hooks
diff options
context:
space:
mode:
Diffstat (limited to 'src/hooks')
-rw-r--r--src/hooks/useWindowWidth.js13
1 files changed, 4 insertions, 9 deletions
diff --git a/src/hooks/useWindowWidth.js b/src/hooks/useWindowWidth.js
index 92bf184..fa79cc4 100644
--- a/src/hooks/useWindowWidth.js
+++ b/src/hooks/useWindowWidth.js
@@ -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