Skip to content

Commit

Permalink
chore: path ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
jpudysz committed Nov 6, 2023
1 parent e651379 commit 043f151
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
21 changes: 15 additions & 6 deletions src/UnistylesTheme.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { createContext } from 'react'
import React, { createContext, useEffect, useState } from 'react'
import type { PropsWithChildren } from 'react'
import { isServer } from './utils'

interface UnistylesThemeProps extends PropsWithChildren {
theme: any
Expand All @@ -10,8 +11,16 @@ export const UnistylesContext = createContext({})
export const UnistylesTheme: React.FunctionComponent<UnistylesThemeProps> = ({
theme,
children
}) => (
<UnistylesContext.Provider value={theme}>
{children}
</UnistylesContext.Provider>
)
}) => {
const [isClient, setIsClient] = useState(!isServer)

useEffect(() => {
setIsClient(true)
}, [])

return (
<UnistylesContext.Provider value={theme}>
{isClient ? children : <React.Fragment /> }
</UnistylesContext.Provider>
)
}
11 changes: 3 additions & 8 deletions src/hooks/useDimensions.web.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { useEffect, 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
? undefined
: window.innerWidth,
height: isServer
? undefined
: window.innerHeight
} as ScreenSize)
width: window.innerWidth,
height: window.innerHeight
})

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

0 comments on commit 043f151

Please sign in to comment.