Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

97
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda