Skip to content

Commit

Permalink
[@mantine/hooks] use-scroll-into-view: Fix parameters changes being i…
Browse files Browse the repository at this point in the history
…gnored (#2866)

* 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/

* Replace tab with 4 spaces

* Remove ref dependency
  • Loading branch information
rChaoz committed Nov 6, 2022
1 parent e0b63a0 commit f83c6a0
Showing 1 changed file with 1 addition and 1 deletion.
Expand Up @@ -111,7 +111,7 @@ export function useScrollIntoView<
}
animateScroll();
},
[scrollableRef.current]
[axis, duration, easing, isList, offset, onScrollFinish, reducedMotion]
);

const handleStop = () => {
Expand Down

0 comments on commit f83c6a0

Please sign in to comment.