Skip to content

Commit 043f151

Browse files
committed
chore: path ssr
1 parent e651379 commit 043f151

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/UnistylesTheme.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import React, { createContext } from 'react'
1+
import React, { createContext, useEffect, useState } from 'react'
22
import type { PropsWithChildren } from 'react'
3+
import { isServer } from './utils'
34

45
interface UnistylesThemeProps extends PropsWithChildren {
56
theme: any
@@ -10,8 +11,16 @@ export const UnistylesContext = createContext({})
1011
export const UnistylesTheme: React.FunctionComponent<UnistylesThemeProps> = ({
1112
theme,
1213
children
13-
}) => (
14-
<UnistylesContext.Provider value={theme}>
15-
{children}
16-
</UnistylesContext.Provider>
17-
)
14+
}) => {
15+
const [isClient, setIsClient] = useState(!isServer)
16+
17+
useEffect(() => {
18+
setIsClient(true)
19+
}, [])
20+
21+
return (
22+
<UnistylesContext.Provider value={theme}>
23+
{isClient ? children : <React.Fragment /> }
24+
</UnistylesContext.Provider>
25+
)
26+
}

src/hooks/useDimensions.web.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
import { useEffect, useRef, useState } from 'react'
22
import type { ScreenSize } from '../types'
3-
import { isServer } from '../utils'
43

54
export const useDimensions = (): ScreenSize => {
65
const timerRef = useRef<ReturnType<typeof setTimeout>>()
76
const [screenSize, setScreenSize] = useState<ScreenSize>({
8-
width: isServer
9-
? undefined
10-
: window.innerWidth,
11-
height: isServer
12-
? undefined
13-
: window.innerHeight
14-
} as ScreenSize)
7+
width: window.innerWidth,
8+
height: window.innerHeight
9+
})
1510

1611
useEffect(() => {
1712
const handleResize = () => {

0 commit comments

Comments
 (0)