From 87388a4a431f6fc4b201373dc13bb85dd7b5ddf7 Mon Sep 17 00:00:00 2001 From: Raj Rohit Yadav Date: Tue, 12 Mar 2024 19:26:39 +0530 Subject: [PATCH] Fix: scrollToIndex out of range: item length 0 but minimum is 1 Error: scrollToIndex out of range: item length 0 but minimum is 1 How to reproduce? 1. Have data of enough length such that on search, the list should scroll 2. Select an item that is not rendered initially when the search is clicked, we have to persist this data for the next re-render 3. On next re-render, open search, and enter string which does not exist in list --- src/components/Dropdown/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Dropdown/index.tsx b/src/components/Dropdown/index.tsx index b5bb13c..b86ea20 100644 --- a/src/components/Dropdown/index.tsx +++ b/src/components/Dropdown/index.tsx @@ -253,7 +253,7 @@ const DropdownComponent: ( const index = _.findIndex(listData, (e: any) => _.isEqual(defaultValue, _.get(e, valueField)) ); - if (index > -1 && index <= listData.length - 1) { + if (index > -1 && !_.isEmpty(listData.length) && index <= listData.length - 1) { refList?.current?.scrollToIndex({ index: index, animated: false,