Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
testing fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
EderOBarreto committed Jul 11, 2022
1 parent 51acdbb commit 7a10713
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/lib/hooks/useWindowDimensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,28 @@ export type WindowDimensions = {
}

function getWindowDimensions(): WindowDimensions {
const { innerWidth: width, innerHeight: height } = window
const width = window?.innerWidth || 0
const height = window?.innerHeight || 0

const rootFontSize = parseInt(getComputedStyle(document.documentElement).fontSize) ?? 16
const rootFontSize = parseInt(getComputedStyle(document?.documentElement)?.fontSize) ?? 16

return {
width: {
px: width,
rem: width / rootFontSize
rem: width / rootFontSize,
},
height: {
px: height,
rem: height / rootFontSize
}
rem: height / rootFontSize,
},
}
}

export const useWindowDimensions = (): WindowDimensions => {
const [windowDimensions, setWindowDimensions] = useState(getWindowDimensions())

useEffect(() => {
function handleResize() {
const handleResize = () => {
setWindowDimensions(getWindowDimensions())
}

Expand All @@ -41,4 +42,4 @@ export const useWindowDimensions = (): WindowDimensions => {
}, [])

return windowDimensions
}
}

0 comments on commit 7a10713

Please sign in to comment.