Relative Content

Tag Archive for next.jsinfinite-scroll

React Custom Infinite scroll trigger request for pages which already fetched

n my implementation of infinite scroll without any library, I encountered a problem within my useEffect. When I scroll to the bottom, it triggers a request for the next set of data, which works perfectly. Initially, if I’m on Page 1 and reach the scroll end, it fetches the response for Page 2 as expected. However, when I scroll to the bottom again to fetch for the next page (Page 3), I noticed that it makes requests for Page 2 and then Page 3. Similarly, on Page 3, it requests Page 2, Page 3, and then Page 4. This results in infinite data being fetched.