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

194
Vistas
reactoring insertBefore in reactjs

I have a button that when clicked wants to insert an element before it. here is the code;

<div><button onClick={(e) => {
    let container = (e.target as HTMLElement).parentNode?.parentNode;
    if (container) {
        let div = document.createElement("div")
        div.classList.add(styles.card)
        container.insertBefore(div, container.lastChild)
        ReactDOM.render(<MyReactElement/>, div)
    }
}}>add</button></div>

This feels terribly sloppy and I want to refactor it so that it uses either all react-dom or all dom, I think this will be a more efficient method. The method above is the only way i've been able to figure out how to achieve the result I am looking for.

about 4 years ago · Juan Pablo Isaza
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