-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e2903d
commit a5aed9b
Showing
2 changed files
with
30 additions
and
33 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
"use client"; | ||
|
||
import { useState, useEffect } from 'react'; | ||
|
||
const ScreenWidth: React.FC = () => { | ||
const [screenWidth, setScreenWidth] = useState<number>(0); | ||
|
||
useEffect(() => { | ||
// Function to update the screen width | ||
const updateWidth = () => setScreenWidth(window.innerWidth); | ||
|
||
// Set the initial width | ||
updateWidth(); | ||
|
||
// Add event listener to track window resize | ||
window.addEventListener('resize', updateWidth); | ||
|
||
// Cleanup event listener on component unmount | ||
return () => window.removeEventListener('resize', updateWidth); | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
<h1>Screen Width: {screenWidth}px</h1> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ScreenWidth; | ||
// "use client"; | ||
// | ||
// import { useState, useEffect } from 'react'; | ||
// | ||
// const ScreenWidth: React.FC = () => { | ||
// const [screenWidth, setScreenWidth] = useState<number>(0); | ||
// | ||
// useEffect(() => { | ||
// // Function to update the screen width | ||
// const updateWidth = () => setScreenWidth(window.innerWidth); | ||
// | ||
// // Set the initial width | ||
// updateWidth(); | ||
// | ||
// // Add event listener to track window resize | ||
// window.addEventListener('resize', updateWidth); | ||
// | ||
// // Cleanup event listener on component unmount | ||
// return () => window.removeEventListener('resize', updateWidth); | ||
// }, []); | ||
// | ||
// return ( | ||
// <div> | ||
// <h1>Screen Width: {screenWidth}px</h1> | ||
// </div> | ||
// ); | ||
// }; | ||
// | ||
// export default ScreenWidth; |