Skip to content

Commit

Permalink
chore: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
jpudysz committed Nov 6, 2023
2 parents bd93bf2 + 4deb55b commit b7093cf
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/hooks/useDimensions.web.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { useEffect, useRef, useState } from 'react'
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
import type { ScreenSize } from '../types'
import { isServer } from '../utils'

export const useDimensions = (): ScreenSize => {
const timerRef = useRef<ReturnType<typeof setTimeout>>()
const [screenSize, setScreenSize] = useState<ScreenSize>({
width: isServer ? 0 : window.innerWidth,
height: isServer ? 0 : window.innerHeight
})
const [screenSize, setScreenSize] = useState<ScreenSize>({} as ScreenSize)

useLayoutEffect(() => {
setScreenSize({
width: window.innerWidth,
height: window.innerHeight
})
}, [])

useEffect(() => {
const handleResize = () => {
Expand Down

0 comments on commit b7093cf

Please sign in to comment.