aboutsummaryrefslogtreecommitdiffstats
path: root/src/hooks
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/hooks/useWindowWidth.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/hooks/useWindowWidth.js b/src/hooks/useWindowWidth.js
new file mode 100644
index 0000000..92bf184
--- /dev/null
+++ b/src/hooks/useWindowWidth.js
@@ -0,0 +1,19 @@
+import { useEffect, useState } from 'react'
+const useWindowWidth = () => {
+ const [windowWidth, setWindowWidth] = useState()
+
+ useEffect(() => {
+ const handleResize = () => {
+ setWindowWidth(window.innerWidth)
+ }
+
+ window.addEventListener('resize', handleResize)
+
+ // Cleanup function to remove the event listener
+ return () => window.removeEventListener('resize', handleResize)
+ }, [])
+
+ return windowWidth
+}
+
+export default useWindowWidth