scrollToIndex Out of range in react native

Viewed 64

I am getting this error one by one on repeat. And because of this my app is closing in live mode. I have 5 to 6 FlatLists and 2 to 3 FlatListSliders in my page where I am getting this error. I do not Know what to do please help. I am applying this code in my code. but it is not working. please help


  const navigationRef = useRef(null);
  const myRef = useRef(null);
  const currentIndex = useRef(0);

  useEffect(() => {
    const timer = setInterval(() => {
      currentIndex.current =
        currentIndex.current === FlatList1.length && FlatLis2.length && FltalIst3.length && ... so on .. FlatList7.length  - 1
          ? 0
          : currentIndex.current + 1;
      myRef?.current?.scrollToIndex({
        animated: true,
        index: currentIndex.current,
      });
    }, 5000);
    return () => clearInterval(timer);
  }, []);
0 Answers
Related