Skip to content

How to use ref in useLayoutEffect with OverlayScrollbarsComponent? #582

Answered by KingSora
krutoo asked this question in Q&A
Discussion options

You must be logged in to vote

Good day @krutoo :)

The OverlayScrollbarsComponent uses exclusively useEffect since useLayoutEffect would trigger warnings on a server environment. Also the react team pushes heavily to use useEffect over useLayoutEffect. This means that its not possible with the OverlayScrollbarsComponent.

Luckily there is the useOverlayScrollbars hook which just gives you the initialize and instance functions so you could do something like this yourself.

export const OverlayScrollbarsLayoutEffectComponent = (props) => {
  const { options, events, defer, children, ...other } = props;
  const elementRef = useRef(null);
  const childrenRef = useRef(null);
  const [initialize, osInstance] = useOverlayScroll…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@krutoo
Comment options

@KingSora
Comment options

@krutoo
Comment options

Answer selected by krutoo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants