Created
March 28, 2021 13:19
-
-
Save code08-ind/b0275f0fbfc935b91639c849ddeaf738 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, { useState, useEffect } from 'react'; | |
import '../node_modules/bootstrap/dist/css/bootstrap.min.css'; | |
import '../node_modules/bootstrap/dist/js/bootstrap.bundle'; | |
const Calculator = () => { | |
const [width, setWidth] = useState(window.screen.width); | |
useEffect(() => { | |
window.addEventListener('resize', changeWidth); | |
console.log("Your Width Is Changed To " + width); | |
return () => { | |
window.removeEventListener('resize', changeWidth); | |
} | |
}, [width]); | |
const changeWidth = () => { | |
setWidth(window.innerWidth); | |
} | |
return ( | |
<> | |
<div className="container"> | |
<h3>Actual Width Of Window Screen Is : </h3> | |
<h1>{width} px</h1> | |
</div> | |
</> | |
); | |
} | |
export default Calculator; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment