question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Infinite Scroll not working when using custom scrollbar

See original GitHub issue

Hi, I really like this library.

I’m trying to use this library with a custom scrollbar but when scrolling at the bottom the function that loads more data does not work

https://codesandbox.io/s/infinite-scroll-w-custom-scrollbar-igdyk

App Component

import React, { useState } from "react";
import { Scrollbar } from "./Scrollbar";
import InfiniteScroll from "react-infinite-scroll-component";
import "./styles.css";



export default function App() {
  const [atpItems, setAtpItems] = useState(Array.from({ length: 20 }));

  const style = {
    height: 30,
    border: "1px solid green",
    margin: 6,
    padding: 8
  };
  const fetchMoreData = () => {
    // a fake async api call like which sends
    // 20 more records in 1.5 secs
    console.log("atpItems.lengthd", atpItems.length);
    if (atpItems.length <= 50) {
      setTimeout(() => {
        setAtpItems(atpItems.concat(Array.from({ length: 5 })));
      }, 1000);
    } else {
    }
  };
  return (
    <div className="App">
      <h1>Infinite Scroll</h1>
      <Scrollbar>
        <InfiniteScroll
          dataLength={atpItems.length}
          next={fetchMoreData}
          hasMore={true}
          loader={<h4>Loading...</h4>}
          endMessage={
            <p style={{ textAlign: "center" }}>
              <b>Yay! You have seen it all</b>
            </p>
          }
        >
          {atpItems.map((i, index) => (
            <div style={style} key={index}>
              div - #{index}
            </div>
          ))}
        </InfiniteScroll>
      </Scrollbar>
    </div>
  );
}

Scrollbar Component

import React from "react";
// import SimpleBar from 'simplebar-react';
import CustomScroll from "react-custom-scroll";
import "./Scrollbar.css";

interface ScrollBarProps {}

export const Scrollbar: React.FC<ScrollBarProps> = ({ children }) => {
  return (
    <CustomScroll allowOuterScroll heightRelativeToParent="400px">
      {children}
    </CustomScroll>
  );
};

What’s the best way to handle this?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
gabe2code-opstalentcommented, Apr 9, 2021

You should use min-height: 30 instead of height. That solved the problem on my side

1reaction
paperfella-ceocommented, Apr 1, 2021

Same problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

Infinite scroll doesn't work when scrolled all the way to the end ...
Infinite scroll doesn't work when scrolled all the way to the end of the div · Could you provide the code that executed...
Read more >
Scrolling | Angular Material
The scrolling package provides helpers for directives that react to scroll events. link cdkScrollable and ScrollDispatcher. The cdkScrollable directive and ...
Read more >
Options - Infinite Scroll
Customize Infinite Scroll with options. ... Disable appending by not setting append , for loading JSON or adding your own append behavior like...
Read more >
Perfect Scrollbar
Finally, scroll hooking is generally considered a bad practice, and perfect-scrollbar should be used carefully. Unless custom scroll is really needed, using ......
Read more >
ScrollArea - Mantine
ScrollArea component is based on Radix UI scroll area component. It is adapted to work well with light and dark color schemes and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found