Skip to content

Commit

Permalink
Fix useScrollIntoView ignoring parameter changes
Browse files Browse the repository at this point in the history
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/
  • Loading branch information
rChaoz committed Nov 2, 2022
1 parent 34dd141 commit 8731560
Showing 1 changed file with 1 addition and 1 deletion.
Expand Up @@ -111,7 +111,7 @@ export function useScrollIntoView<
}
animateScroll();
},
[scrollableRef.current]
[scrollableRef, axis, duration, easing, isList, offset, onScrollFinish, reducedMotion]
);

const handleStop = () => {
Expand Down

0 comments on commit 8731560

Please sign in to comment.