-
Hi, i m trying to use But in Its defined only in I use viewport element for properly blocking page scroll when my modal is shown. Layout effect is needed because otherwise when switching modals there is scroll bar blinking |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Good day @krutoo :) The Luckily there is the export const OverlayScrollbarsLayoutEffectComponent = (props) => {
const { options, events, defer, children, ...other } = props;
const elementRef = useRef(null);
const childrenRef = useRef(null);
const [initialize, osInstance] = useOverlayScrollbars({ options, events, defer });
useLayoutEffect(() => {
const { current: elm } = elementRef;
const { current: childrenElm } = childrenRef;
if (elm && childrenElm) {
initialize({
target: elm,
elements: {
viewport: childrenElm,
content: childrenElm,
},
});
}
return () => osInstance()?.destroy();
}, [initialize, osInstance]);
return (
<div data-overlayscrollbars-initialize="" ref={elementRef} {...other}>
<div data-overlayscrollbars-contents="" ref={childrenRef}>
{children}
</div>
</div>
);
} |
Beta Was this translation helpful? Give feedback.
Good day @krutoo :)
The
OverlayScrollbarsComponent
uses exclusivelyuseEffect
sinceuseLayoutEffect
would trigger warnings on a server environment. Also the react team pushes heavily to useuseEffect
overuseLayoutEffect
. This means that its not possible with theOverlayScrollbarsComponent
.Luckily there is the
useOverlayScrollbars
hook which just gives you the initialize and instance functions so you could do something like this yourself.