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

210
Visualizações
React js : items never fed in infinite scroll (now with simpler example)

I've got a small problem with "react-infinite-scroller". I'm using the code below :

function RadioStations(props) {
  const [items, setItems] = useState(new Array());
  const [hasMore, setHasMore] = useState(true);
  let { filter, fname } = useParams();

  return (
    <div style={{ height: "700px", overflow: "auto" }}>
      <InfiniteScroll
        pageStart={0}
        loadMore={() => {
          items.push(<div>Test</div>);
          console.log(items);
          setItems(items);
          setHasMore(false);
        }}
        hasMore={hasMore}
        loader={
          <div className="loader" key={0}>
            Loading ...
          </div>
        }
        useWindow={false}
      >
        {items}
      </InfiniteScroll>
    </div>
  );
}

As I can see, my loadMore function is fired, but I never get my items to appear and I wondering why.

Any help would be welcome.

Thank you.

Edit:I've simplified the example.

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

0

If you using map , you need to return something

Try to add a return is this line :

let jsonItems = json.map((data) =>{ return  <Station data={data} />});
about 4 years ago · Juan Pablo Isaza Relatório

0

Found it. I need to add a div inside the infinite scroll.

function RadioStations(props) {
  const [items, setItems] = useState(new Array());
  const [hasMore, setHasMore] = useState(true);
  let { filter, fname } = useParams();

  return (
    <div style={{ height: "700px", overflow: "auto" }}>
      <InfiniteScroll
        pageStart={0}
        loadMore={() => {
          items.push(<div>Test</div>);
          console.log(items);
          setItems(items);
          setHasMore(false);
        }}
        hasMore={hasMore}
        loader={
          <div className="loader" key={0}>
            Loading ...
          </div>
        }
        useWindow={false}
      >
      <div>
        {items}
      </div>
    </InfiniteScroll>
    </div>
  );
}


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