2024-08-27
1906
#react
Ogundipe Samuel
1837
Aug 27, 2024 â‹… 6 min read

What is infinite scrolling: Implementing it in React

Ogundipe Samuel Software engineer and technical writer.

Recent posts:

Leaflet Adoption Guide: Overview, Examples, And Alternatives

Leaflet adoption guide: Overview, examples, and alternatives

Leaflet is a handy, lightweight, performant JavaScript library for creating responsive and interactive maps for the web.

Joseph Mawa
Sep 19, 2024 â‹… 11 min read
JavaScript logo with glowing lights, representing secure web authentication. Learn how JWT, OAuth, and Bearer tokens enhance modern authentication methods.

Understanding JWT, OAuth, and Bearer tokens

If you were to meet your friend in the street, straight away you would likely greet them and ask them […]

Lewis Cianci
Sep 19, 2024 â‹… 5 min read
An illustration of a hand holding a large hammer with a lightning bolt symbol. The background features a vibrant, gradient sky with shining stars. This image metaphorically represents the strength and flexibility of using Vike and vite-plugin-federation to build scalable micro-frontends. As discussed in the article, Vike allows for server-side rendering (SSR) and static-site generation (SSG), while vite-plugin-federation helps integrate shared components across different micro-frontend applications, enhancing the speed and modularity of modern web development frameworks like React, Vue, and Svelte

How to build scalable micro-frontends with Vike and Vite

Micro-frontends let you split a large web application into smaller, manageable pieces. It’s an approach inspired by the microservice architecture […]

Elijah Asaolu
Sep 18, 2024 â‹… 6 min read
Nitro: Revolutionizing Server-Side JavaScript

Nitro.js: Revolutionizing server-side JavaScript

Nitro.js is a solution in the server-side JavaScript landscape that offers features like universal deployment, auto-imports, and file-based routing.

Iniubong Obonguko
Sep 16, 2024 â‹… 11 min read
View all posts

2 Replies to "What is infinite scrolling: Implementing it in React"

  1. Hi,
    Thanks,

    I followed you & implemented the infinite scroll. I have been facing this issue.
    I have set page size 30, So for each API response I receive the 30 data. The problem is, when I open the application in big screen like TV/projector, Initial API call loads the 30 data & no scroll appear due to large screen. But I have 1000 data in Database.

    I told team, We could increase the initial page size 100, then they asked suppose after increased size What If the scroll doesn’t appear on window. More over, they want to keep page size 30 only, do not want to change.

    How to solve when I open the application in big screen, load the data until scroll appear?

  2. This error occured because you did not specify the context in which the infinite scroll should work. It defaults to the viewport if not set.

    The solution is that you pass in the root which is a selector to the options object as shown below.

    let options = {
    root: document.querySelector(“#scrollArea”),
    rootMargin: “0px”,
    threshold: 1.0,
    };

    let observer = new IntersectionObserver(callback, options);

Leave a Reply