forked from xola/ui-kit
-
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
3 changed files
with
39 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { useState, useEffect } from "react"; | ||
|
||
export const useViewportHeight = () => { | ||
const [viewportHeight, setViewportHeight] = useState(0); | ||
const [viewportHeight, setViewportHeight] = useState(0); | ||
|
||
useEffect(() => { | ||
const detectViewportHeight = () => { | ||
// Use window.innerHeight for a more accurate viewport height | ||
setViewportHeight(window.innerHeight); | ||
}; | ||
useEffect(() => { | ||
const detectViewportHeight = () => { | ||
// Use window.innerHeight for a more accurate viewport height | ||
// eslint-disable-next-line no-undef | ||
setViewportHeight(window.innerHeight); | ||
}; | ||
|
||
// Detect height on mount | ||
detectViewportHeight(); | ||
// Detect height on mount | ||
detectViewportHeight(); | ||
|
||
// Optional: Re-detect on orientation change for mobile devices | ||
window.addEventListener('orientationchange', detectViewportHeight); | ||
// Optional: Re-detect on orientation change for mobile devices | ||
// eslint-disable-next-line no-undef | ||
window.addEventListener("orientationchange", detectViewportHeight); | ||
|
||
return () => { | ||
window.removeEventListener('orientationchange', detectViewportHeight); | ||
}; | ||
}, []); | ||
return () => { | ||
// eslint-disable-next-line no-undef | ||
window.removeEventListener("orientationchange", detectViewportHeight); | ||
}; | ||
}, []); | ||
|
||
return viewportHeight; | ||
}; | ||
return viewportHeight; | ||
}; |