import React from 'react'
function MyComponent() {
const [dimensions, setDimensions] = React.useState({
height: window.innerHeight,
width: window.innerWidth
})
React.useEffect(() => {
function handleResize() {
setDimensions({
height: window.innerHeight,
width: window.innerWidth
})
}
window.addEventListener('resize', handleResize)
return _ => {
window.removeEventListener('resize', handleResize)
}
})
return <div>Rendered at {dimensions.width} x {dimensions.height}</div>
}