I want to change only one item per scroll. How can I do in React-Native Flatlist
I am getting an error while using this method
Error: Invariant Violation: scrollToIndex out of range: requested index 5 but maximum is 4
const flatListRef = useRef(null);
const [currentIndex, setCurrentIndex] = useState(1);
const _onScrolIndexChange = () => {
flatListRef.current.scrollToIndex({ animated: true, index: 1 });
setCurrentIndex(currentIndex + 1);
};
<FlatList
ref={flatListRef}
data={list}
onScroll={_onScrolIndexChange}
/>
Thanks for helping