2021-09-21
3223
#react
Luke Denton
67598
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:

TypeScript logo over a pink and white background.

Drizzle vs. Prisma: Which ORM is best for your project?

Compare Prisma and Drizzle ORMs to learn their differences, strengths, and weaknesses for data access and migrations.

Temitope Oyedele
Nov 21, 2024 ⋅ 10 min read
Practical Implementation Of The Rule Of Least Power For Developers

Practical implementation of the Rule of Least Power for developers

It’s easy for devs to default to JavaScript to fix every problem. Let’s use the RoLP to find simpler alternatives with HTML and CSS.

Timonwa Akintokun
Nov 21, 2024 ⋅ 8 min read
Rust logo over black marble background.

Handling memory leaks in Rust

Learn how to manage memory leaks in Rust, avoid unsafe behavior, and use tools like weak references to ensure efficient programs.

Ukeje Goodness
Nov 20, 2024 ⋅ 4 min read
Robot pretending to be a person.

Using curl-impersonate in Node.js to avoid blocks

Bypass anti-bot measures in Node.js with curl-impersonate. Learn how it mimics browsers to overcome bot detection for web scraping.

Antonello Zanini
Nov 20, 2024 ⋅ 13 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