From a24134f8525373f5707b6c48aa77d3f4aff70799 Mon Sep 17 00:00:00 2001 From: Mo Tarbin Date: Tue, 9 Jul 2024 17:39:16 -0400 Subject: Add useWindowWidth hook and HistoryCard component --- src/hooks/useWindowWidth.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/hooks/useWindowWidth.js (limited to 'src/hooks') 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 -- cgit