Skip to content

Instantly share code, notes, and snippets.

@lilpolymath
Created August 4, 2020 16:22
Show Gist options
  • Save lilpolymath/c5ee2c6ed79f8079462a09020f691115 to your computer and use it in GitHub Desktop.
Save lilpolymath/c5ee2c6ed79f8079462a09020f691115 to your computer and use it in GitHub Desktop.
import React, { useState, useEffect } from "react";
export default function App() {
const [windowWidth, setWindowWidth] = useState(window.innerWidth);
const resizeHandler = () => {
setWindowWidth(window.innerWidth);
};
useEffect(() => {
window.addEventListener("resize", resizeHandler);
}, []);
return (
<div>
{windowWidth}
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment