Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

189
Visualizações
How to check if scroll is near the bottom

I have Dropdown list in my React app: when scrolling on the bottom I'm fetching next elements from backend so my dropdown list is dynamic. I want to know if I'm on the bottom of the list - then I want to fetch next elements. How to check if it's time to fetch next elements?

<Content>
        <MySelectField onClick={handleOnClick} onScroll={handleOnScroll}>
function handleOnScroll(e) {
        const { scrollTop, scrollHeight, offsetHeight } = e.target;
        if (offsetHeight - scrollTop < 50) {
            handleLoadNextElements();
        }
    }

What conditions should I use to fetch next elements when I'm on teh bottom of my scrollable list?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

This should work for a vertical scroll. Solution based on Detecting when user scrolls to bottom of div with React js

function handleOnScroll(e) {
    const bottom = e.target.scrollHeight - e.target.clientHeight <= e.target.scrollTop + 50;
    if (bottom) {
        handleLoadNextElements();
    }
}

If you want full compatibility with mobile you might want to take a look of this library, it works perfectly on mobile. react-bottom-scroll-listener

about 4 years ago · Juan Pablo Isaza Relatório

0

I fixed my problem by adding onScroll to my div:

 <TemplateSelectField
                    onClick={handleOnClick}
                    onScroll={handleOnScroll}
                >

and then:

function handleOnScroll(e) {
        const { scrollTop, scrollHeight, offsetHeight } = e.target;
        const hasScrollReachedBottom =
            offsetHeight + scrollTop > scrollHeight - 40;

        if (hasScrollReachedBottom) {
            handleLoad();
        }
    }

Works excellent:)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda