Skip to content

Commit 5d64e3e

Browse files
Fix misuse of second argument as nextState (the actual argument is prevState)
This fixes instances where, right after scrolling, a change in the `scrollToIndex` prop will not actually scroll to the item at the passed index correctly. This is due to the `componentDidUpdate` method considering the previous state to actually be the next state and looking at `scrollChangeReason` on it, seeing the old `scrollChangeReason` caused by the user scrolling, thus not calling `scrollTo` to actually center the element.
1 parent 0b446dc commit 5d64e3e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ export default class VirtualList extends React.PureComponent<Props, State> {
183183
}
184184
}
185185

186-
componentDidUpdate(_: Props, nextState: State) {
187-
const {offset} = this.state;
186+
componentDidUpdate(_: Props, prevState: State) {
187+
const {offset, scrollChangeReason} = this.state;
188188

189-
if (nextState.offset !== offset && nextState.scrollChangeReason === SCROLL_CHANGE_REQUESTED) {
189+
if (prevState.offset !== offset && scrollChangeReason === SCROLL_CHANGE_REQUESTED) {
190190
this.scrollTo(offset);
191191
}
192192
}

0 commit comments

Comments
 (0)