diff --git a/lib/smooth-scrollbar.ts b/lib/smooth-scrollbar.ts index 6806780..ad8d5aa 100644 --- a/lib/smooth-scrollbar.ts +++ b/lib/smooth-scrollbar.ts @@ -46,9 +46,6 @@ const SmoothScrollbarReact = forwardRef( }, []); useEffect(() => { - if (ref) { - (ref as React.MutableRefObject).current = scrollbar.current; - } return () => { if (scrollbar.current) { scrollbar.current.removeListener(handleScroll); @@ -57,6 +54,12 @@ const SmoothScrollbarReact = forwardRef( }; }, []); + useEffect(() => { + if (ref) { + (ref as React.MutableRefObject).current = scrollbar.current; + } + }, [scrollbar.current]); + useEffect(() => { if (mountedRef.current === true) { if (scrollbar.current) {