Skip to content

Commit

Permalink
Merge pull request #45 from KATT/master
Browse files Browse the repository at this point in the history
Small optimizations
  • Loading branch information
mvasin authored Sep 25, 2020
2 parents a8eff40 + 25994ca commit d961353
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/react-div-100vh/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function Div100vh({
}

export function use100vh(): number | null {
const [height, setHeight] = useState<number | null>(measureHeight())
const [height, setHeight] = useState<number | null>(measureHeight)

const wasRenderedOnClientAtLeastOnce = useWasRenderedOnClientAtLeastOnce()

Expand All @@ -32,12 +32,12 @@ export function use100vh(): number | null {

function setMeasuredHeight() {
const measuredHeight = measureHeight()
if (height !== measuredHeight) setHeight(measuredHeight)
setHeight(measuredHeight)
}

window.addEventListener('resize', setMeasuredHeight)
return () => window.removeEventListener('resize', setMeasuredHeight)
}, [height, wasRenderedOnClientAtLeastOnce])
}, [wasRenderedOnClientAtLeastOnce])
return wasRenderedOnClientAtLeastOnce ? height : null
}

Expand All @@ -57,10 +57,10 @@ function useWasRenderedOnClientAtLeastOnce() {
] = useState(false)

useEffect(() => {
if (isClient() && !wasRenderedOnClientAtLeastOnce) {
if (isClient()) {
setWasRenderedOnClientAtLeastOnce(true)
}
}, [wasRenderedOnClientAtLeastOnce])
}, [])
return wasRenderedOnClientAtLeastOnce
}

Expand Down

1 comment on commit d961353

@vercel
Copy link

@vercel vercel bot commented on d961353 Sep 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.