diff --git a/packages/react-div-100vh/src/index.tsx b/packages/react-div-100vh/src/index.tsx index 0dd4b3f..1f9139f 100644 --- a/packages/react-div-100vh/src/index.tsx +++ b/packages/react-div-100vh/src/index.tsx @@ -23,7 +23,7 @@ export default function Div100vh({ } export function use100vh(): number | null { - const [height, setHeight] = useState(measureHeight()) + const [height, setHeight] = useState(measureHeight) const wasRenderedOnClientAtLeastOnce = useWasRenderedOnClientAtLeastOnce() @@ -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 } @@ -57,10 +57,10 @@ function useWasRenderedOnClientAtLeastOnce() { ] = useState(false) useEffect(() => { - if (isClient() && !wasRenderedOnClientAtLeastOnce) { + if (isClient()) { setWasRenderedOnClientAtLeastOnce(true) } - }, [wasRenderedOnClientAtLeastOnce]) + }, []) return wasRenderedOnClientAtLeastOnce }