From 0e187f93a48011e14ad45dc8d0e50249e4d65e3a Mon Sep 17 00:00:00 2001 From: Welly Shen Date: Thu, 3 Jun 2021 22:00:21 +0800 Subject: [PATCH] fix: the callback of `scrollToItem` is called twice --- .changeset/stale-glasses-wonder.md | 5 +++++ src/useVirtual.ts | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .changeset/stale-glasses-wonder.md diff --git a/.changeset/stale-glasses-wonder.md b/.changeset/stale-glasses-wonder.md new file mode 100644 index 00000000..4bb9a978 --- /dev/null +++ b/.changeset/stale-glasses-wonder.md @@ -0,0 +1,5 @@ +--- +"react-cool-virtual": patch +--- + +fix: the callback of `scrollToItem` is called twice diff --git a/src/useVirtual.ts b/src/useVirtual.ts index 2c75d6a7..3fc3632a 100644 --- a/src/useVirtual.ts +++ b/src/useVirtual.ts @@ -232,11 +232,14 @@ export default < if ( hasDynamicSizeRef.current && + align === Align.auto && scrollOffset <= start && scrollOffset + outerSize >= end && cb - ) + ) { cb(); + return; + } const endPos = start - outerSize + size;