Skip to content

Commit

Permalink
Fix react server warning
Browse files Browse the repository at this point in the history
  • Loading branch information
damassi committed May 27, 2020
1 parent 4b013c5 commit fb609db
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/v2/Utils/Hooks/useWindowSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { getViewportDimensions } from "v2/Utils/viewport"
export const useWindowSize = () => {
const [size, setSize] = useState({ width: 0, height: 0 })

if (typeof window === "undefined") {
return size
}

useLayoutEffect(() => {
function resize() {
const { width, height } = getViewportDimensions()
Expand All @@ -15,9 +19,5 @@ export const useWindowSize = () => {
return () => window.removeEventListener("resize", resize)
}, [])

if (typeof window === "undefined") {
return { width: 0, height: 0 }
}

return size
}

0 comments on commit fb609db

Please sign in to comment.