-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
11 changed files
with
105 additions
and
52 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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use client' | ||
import { useEffect, useState } from 'react' | ||
|
||
interface ScreenInfo { | ||
isMobile: boolean | ||
width: number | ||
height: number | ||
} | ||
|
||
/** | ||
* Custom hook to check if the screen size is mobile and to track screen width and height. | ||
* | ||
* @returns An object containing: | ||
* - `isMobile`: A boolean indicating if the screen width is 768px or less. | ||
* - `width`: The current screen width in pixels. | ||
* - `height`: The current screen height in pixels. | ||
* | ||
* @example | ||
* const { isMobile, width, height } = useMobileCheck(); | ||
* console.log(isMobile); // true if the screen width is 768px or less | ||
* | ||
* @remarks | ||
* - Adds an event listener to `window.resize` to update the screen information on resize. | ||
* - Automatically removes the event listener when the component using this hook unmounts. | ||
*/ | ||
|
||
export const useMobileCheck = (): ScreenInfo => { | ||
const [screenInfo, setScreenInfo] = useState<ScreenInfo>({ | ||
isMobile: window.innerWidth <= 768, | ||
width: window.innerWidth, | ||
height: window.innerHeight, | ||
}) | ||
|
||
useEffect(() => { | ||
const handleResize = () => { | ||
setScreenInfo({ | ||
isMobile: window.innerWidth <= 768, | ||
width: window.innerWidth, | ||
height: window.innerHeight, | ||
}) | ||
} | ||
|
||
window.addEventListener('resize', handleResize) | ||
|
||
return () => window.removeEventListener('resize', handleResize) | ||
}, []) | ||
|
||
return screenInfo | ||
} |
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