aboutsummaryrefslogtreecommitdiffstats
path: root/src/hooks
diff options
context:
space:
mode:
authorLibravatar Mo Tarbin <mhed.t91@gmail.com>2024-07-09 17:50:57 -0400
committerLibravatar Mo Tarbin <mhed.t91@gmail.com>2024-07-09 17:50:57 -0400
commit8da220e990b5ab15509848d4d7a57298eb6e808e (patch)
treeafdba1cf49031afe70f4f9ffbc84416370919a95 /src/hooks
parent40f1384dfc5ad012b8f47514a07f350141bdf35e (diff)
downloaddonetick-frontend-8da220e990b5ab15509848d4d7a57298eb6e808e.tar.gz
donetick-frontend-8da220e990b5ab15509848d4d7a57298eb6e808e.tar.bz2
donetick-frontend-8da220e990b5ab15509848d4d7a57298eb6e808e.zip
Refactor useWindowWidth hook to improve readability
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