Created
August 4, 2020 16:22
-
-
Save lilpolymath/c5ee2c6ed79f8079462a09020f691115 to your computer and use it in GitHub Desktop.
This file contains hidden or 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, { 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