diff --git a/src/hooks/useDimensions.web.ts b/src/hooks/useDimensions.web.ts index c8b02dfe..7a023e77 100644 --- a/src/hooks/useDimensions.web.ts +++ b/src/hooks/useDimensions.web.ts @@ -1,7 +1,15 @@ import { useEffect, useRef, useState } from 'react' import type { ScreenSize } from '../types' +import { isServer } from '../utils' export const useDimensions = (): ScreenSize => { + if (isServer()) { + return { + width: 0, + height: 0 + } + } + const timerRef = useRef>() const [screenSize, setScreenSize] = useState({ width: window.innerWidth, diff --git a/src/utils/common.ts b/src/utils/common.ts index b3b6534f..2421e04f 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -9,3 +9,4 @@ export const warn = (message: string) => { } export const isWeb = () => Platform.OS === 'web' +export const isServer = () => typeof window === 'undefined' diff --git a/src/utils/index.ts b/src/utils/index.ts index 0cff90a2..abd69664 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -2,6 +2,7 @@ export { normalizeStyles } from './normalizeStyles' export * from './normalizer' export { getBreakpointFromScreenWidth, sortAndValidateBreakpoints, getValueForBreakpoint } from './breakpoints' export { proxifyFunction, parseStyle } from './styles' +export { isServer } from './common' export { extractValues, getKeyForCustomMediaQuery,