From 87315604aba029cd209342fb6d49a17912ad0357 Mon Sep 17 00:00:00 2001 From: Matei Trandafir <8215371+rChaoz@users.noreply.github.com> Date: Wed, 2 Nov 2022 16:18:12 +0200 Subject: [PATCH] Fix useScrollIntoView ignoring parameter changes Currently, useScrollIntoView returns a memoized callback that always refers to the params passed during the first render of the calling component, so calling with dynamically computed params, e.g. useScrollIntoView({ offset: someVariable }) will memoize the offset passed during the first render. If the component re-renders, any new offset passed is ignored. Aditionally, 'scrollableRef.current' is an invalid dependency, see https://epicreact.dev/why-you-shouldnt-put-refs-in-a-dependency-array/ --- .../src/use-scroll-into-view/use-scroll-into-view.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mantine-hooks/src/use-scroll-into-view/use-scroll-into-view.ts b/src/mantine-hooks/src/use-scroll-into-view/use-scroll-into-view.ts index 31203047261..66383fbb527 100644 --- a/src/mantine-hooks/src/use-scroll-into-view/use-scroll-into-view.ts +++ b/src/mantine-hooks/src/use-scroll-into-view/use-scroll-into-view.ts @@ -111,7 +111,7 @@ export function useScrollIntoView< } animateScroll(); }, - [scrollableRef.current] + [scrollableRef, axis, duration, easing, isList, offset, onScrollFinish, reducedMotion] ); const handleStop = () => {