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

98
Visualizações
Ensure a component is rendered after DOM update

I have a ScrollBar that receives the CardsContainer as a ref in order to be able to display some HTML elements under it that allow for some custom scroll behavior.

The issue is, even if the state is updated and the cards are rerendered, the ScrollBar will still receive the old node because the node is creating while ScrollBar is rendered. How could I get around this?

  return (
        <div>
            <CardsContainer ref={nodeRef}>
              {cards.map((card, index) => (
                <Card
                  {...card}
                  index={index}
                  onClickDismiss={handleDismiss}
                />
              ))}
            </CardsContainer>
            <ScrollBar container={nodeRef} />
          </>
        </div>
      )

where

  const handleDismiss = (index: number) => {
    setCards([...cards.filter((c, i) => i !== index)])
  }

P.S. As requested, code of a button click event handler inside ScrollBar:

  const onClickRightArrow = () => {
    isArrowScroll.current = true
    if (activeIndex < container.children.length - 1) {
      container.children[activeIndex + 1].scrollIntoView({
        behavior: 'smooth',
        block: 'nearest',
        inline: 'center',
      })
      setActiveIndex(activeIndex + 1)
    }
  }
about 4 years ago · Santiago Gelvez
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