I want to change only one item per scroll. How can I do in React-Native Flatlist

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

I solved the problem.

Solution to the problem

<FlatList
ref={flatListRef}
data={list}
disableIntervalMomentum
…props
/>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.