Skip to content

Commit 10886ea

Browse files
committed
fix: make useBreakpoint ssr-safe
1 parent a63e36d commit 10886ea

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/components/newPdfViewer.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ interface WheelZoomProps {
3737
}
3838

3939
function useBreakpoint() {
40-
const [width, setWidth] = useState(() => window.innerWidth);
40+
const [width, setWidth] = useState<number | null>(null);
4141

4242
useEffect(() => {
4343
setWidth(window.innerWidth);
4444
const handler = () => setWidth(window.innerWidth);
4545
window.addEventListener("resize", handler);
4646
return () => window.removeEventListener("resize", handler);
4747
}, []);
48-
49-
return {isMobile: width < 768, isSmall: width < 640};
48+
49+
return {isMobile: width !== null && width < 768, isSmall: width !== null && width < 640};
5050
}
5151

5252
const Controls = memo(function Controls({documentId, toggleFullscreen, isFullscreen, onDownload,

0 commit comments

Comments
 (0)