react-native-element-dropdown
react-native-element-dropdown copied to clipboard
Invariant Violation: scrollToIndex out of range: requested index 28 is out of 0 to 1, js engine: hermes
I solved this inside the Dropdows.tsx Index file
const scrollIndex = useCallback(() => {
if (autoScroll && data.length > 0 && listData?.length === data?.length) {
setTimeout(() => {
if (refList && refList?.current) {
const defaultValue = typeof value === 'object' ? _.get(value, valueField) : value;
const index = _.findIndex(listData, (e) => _.isEqual(defaultValue, _.get(e, valueField)));
if (index > -1 && index < listData.length) {
try {
refList.current.scrollToIndex({
index: index,
animated: false,
});
} catch (error) {
console.warn(`scrollToIndex error: ${error.message}`);
}
} else {
console.warn(`scrollToIndex out of range: requested index ${index} is out of 0 to ${listData.length - 1}`);
}
}
}, 200);
}
}, [autoScroll, data.length, listData, value, valueField, refList]);
getting this error, again and again, need to be fixed, @gabrielroodriz you code converted the mi into warning but it's not worthy to edit in node modules for local use until it's merged in the library.
Yes, I have a pull request open, waiting for approval for it: https://github.com/hoaphantn7604/react-native-element-dropdown/pull/279
Hi @gabrielroodriz , I faced this error. And apply your above file to my Dropdown index.tsx. It worked, but which selected it's not get select in my dropdown as a selected city its not appeared. What should i do?
It bug was fixed on the version 2.10.4: