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