Created
August 6, 2020 17:01
-
-
Save Alimjanov-Ibragim/f24c94ef9ef2c782b6c7c7993b10357c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect, useState } from "react"; | |
let App = () => { | |
const [windowWidth, setWindowWidth] = useState(0); | |
const [windowHeight, setWindowHeight] = useState(0); | |
let resizeWindow = () => { | |
setWindowWidth(window.innerWidth); | |
setWindowHeight(window.innerHeight); | |
}; | |
useEffect(() => { | |
resizeWindow(); | |
window.addEventListener("resize", resizeWindow); | |
return () => window.removeEventListener("resize", resizeWindow); | |
}, []); | |
return ( | |
<div> | |
<span> | |
{windowWidth} x {windowHeight} | |
</span> | |
</div> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment