Skip to content

Commit

Permalink
Merge pull request #30 from bernhardoj/update-container-height
Browse files Browse the repository at this point in the history
Dynamically update container height
  • Loading branch information
mountiny committed Jul 5, 2024
2 parents 1abc4ed + 403121d commit b5534c7
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/PDFPreviewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,19 @@ function PDFPreviewer({
}, [isPasswordInvalid, attemptPDFLoad, setIsPasswordInvalid, renderPasswordForm]);

useLayoutEffect(() => {
setContainerWidth(containerRef.current?.clientWidth ?? 0);
setContainerHeight(containerRef.current?.clientHeight ?? 0);
if (!containerRef.current) {
return undefined;
}
const resizeObserver = new ResizeObserver(() => {
if (!containerRef.current) {
return;
}
setContainerWidth(containerRef.current.clientWidth);
setContainerHeight(containerRef.current.clientHeight);
});
resizeObserver.observe(containerRef.current);

return () => resizeObserver.disconnect();
}, []);

return (
Expand Down

0 comments on commit b5534c7

Please sign in to comment.