17 lines
605 B
JavaScript
17 lines
605 B
JavaScript
import { scrollbarWidth } from '@xobotyi/scrollbar-width';
|
|
import { useEffect, useState } from 'react';
|
|
export function useScrollbarWidth() {
|
|
var _a = useState(scrollbarWidth()), sbw = _a[0], setSbw = _a[1];
|
|
// this needed to ensure the scrollbar width in case hook called before the DOM is ready
|
|
useEffect(function () {
|
|
if (typeof sbw !== 'undefined') {
|
|
return;
|
|
}
|
|
var raf = requestAnimationFrame(function () {
|
|
setSbw(scrollbarWidth());
|
|
});
|
|
return function () { return cancelAnimationFrame(raf); };
|
|
}, []);
|
|
return sbw;
|
|
}
|