Luke Denton
Sep 21, 2021 ⋅ 11 min read

React Hooks for infinite scroll: An advanced tutorial

Luke Denton A software engineer at Aligent Consulting with a passion for writing accessible code. I create React JS e-commerce sites every day, while taking on a leadership and mentoring role for the rest of the developers in the company.

Recent posts:

Implementing Vector Search With Open Ai, Next Js, And Supabase

Implementing vector search with OpenAI, Next.js, and Supabase

Let’s build a Next.js app that implements vector search using Supabase and OpenAI to offer better search experiences for users.

Peter Ekene Eze
Feb 27, 2024 ⋅ 11 min read
Comparing React Native BLE libraries

Comparing React Native BLE libraries

Discover the most popular libraries for enabling Bluetooth Low Energy (BLE) in React Native apps, allowing them to interact with Bluetooth hardware on iOS and Android platforms.

Fimber Elemuwa
Feb 26, 2024 ⋅ 4 min read
Using CRDTs To Build Collaborative Rust Web Applications

Using CRDTs to build collaborative Rust web applications

CRDTs, or conflict-free replicated data types, is a concept that underlies applications facing the issue of data replication across a […]

Mario Zupan
Feb 23, 2024 ⋅ 15 min read
Guide to Using TensorFlow in Rust

Guide to using TensorFlow in Rust

We explore the fusion of TensorFlow and Rust, delving into how we can integrate these two technologies to build and train a neural network.

Rosario De Chiara
Feb 22, 2024 ⋅ 8 min read
View all posts

3 Replies to "React Hooks for infinite scroll: An advanced tutorial"

  1. This useEffect makes no sense, since you have a new loadItems instance in dependency array every render, the effect will execute all renders. You would get the same result without it, or improving the loadItems method

    1. Hey Rhoger! Thanks for pointing that out, you’re absolutely correct. While the loadItems function itself isn’t going to run on every render, as it’s “protected” by the ref, the useEffect hook will, which could definitely be optimised a bit better. This is what happens when trying to anticipate what the exhaustive deps eslint rule would indicate, without actually using a linter when writing the code 😬.
      To fix, we could either remove loadItems from the dependency array of the useEffect hook, and then add an eslint-disable-line comment, or we could wrap the loadItems function in a useCallback hook.

      Thanks again!

Leave a Reply