Skip to content

Instantly share code, notes, and snippets.

@Alimjanov-Ibragim
Created August 6, 2020 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alimjanov-Ibragim/f24c94ef9ef2c782b6c7c7993b10357c to your computer and use it in GitHub Desktop.
Save Alimjanov-Ibragim/f24c94ef9ef2c782b6c7c7993b10357c to your computer and use it in GitHub Desktop.
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