mirror of
https://github.com/status-im/nimbus-gui.git
synced 2025-01-21 00:40:09 +00:00
feat: create custom hook for window size
This commit is contained in:
parent
0c610343d1
commit
5ca1529dc1
22
src/hooks/useWindowSize.ts
Normal file
22
src/hooks/useWindowSize.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
|
||||
export const useWindowSize = () => {
|
||||
const [size, setSize] = useState({ width: 0, height: 0 })
|
||||
|
||||
useEffect(() => {
|
||||
function handleResize() {
|
||||
setSize({
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
})
|
||||
}
|
||||
|
||||
window.addEventListener('resize', handleResize)
|
||||
|
||||
handleResize()
|
||||
|
||||
return () => window.removeEventListener('resize', handleResize)
|
||||
}, [])
|
||||
|
||||
return size
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user