Always use calculated scrollbar size

This commit is contained in:
schroda
2024-09-06 23:50:38 +02:00
parent d9777c179a
commit 4662a9175f
5 changed files with 18 additions and 8 deletions

View File

@@ -27,12 +27,18 @@ export class MediaQuery {
return this.useIsBelowWidth('sm');
}
static useGetScrollbarSize(): number {
static useGetScrollbarSize(type: 'height' | 'width'): number {
const [scrollbarSize, setScrollbarSize] = useState(0);
useResizeObserver(
document.documentElement,
useCallback(() => setScrollbarSize(window.innerHeight - document.documentElement.clientHeight), []),
useCallback(() => {
const height = window.innerHeight - document.documentElement.clientHeight;
const width = window.innerWidth - document.documentElement.clientWidth;
const size = type === 'height' ? height : width;
setScrollbarSize(size);
}, []),
);
return scrollbarSize;