Created
January 11, 2022 07:37
-
-
Save salmanx/923eb57e4552287b5bed9bfb1230f621 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, { useEffect, useState } from "react"; | |
export default function WindowResize() { | |
const [windowWidth, setWindowWidth] = useState(window.innerWidth); | |
const handleWindowResize = () => setWindowWidth(window.innerWidth) | |
useEffect(() => { | |
window.addEventListener('resize', handleWindowResize); | |
return () => { | |
window.removeEventListener('resize', handleWindowResize); | |
} | |
}, []) | |
return( | |
<div> | |
{windowWidth} | |
</div> | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment