Add useWindowWidth hook and HistoryCard component
This commit is contained in:
parent
c4bf06b11c
commit
a24134f852
4 changed files with 157 additions and 105 deletions
19
src/hooks/useWindowWidth.js
Normal file
19
src/hooks/useWindowWidth.js
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue