• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

106
Vistas
How to render between two elements in React?

Here's the original HTML:

<div class="chat">
    <div class="uploadArea">
        ...
    </div>
    <section class="title">
        ...
    </section>
    <div class="content">
        ...
    </div>
</div>

I want to render a component between the title and the content. How can I do that?

ReactDOM.render(Component, document.getElementsByClassName("chat")[0]);

wouldn't really work, right?

almost 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Create an element which you can use as the container for you react application. Insert the created element in the position you want, like in this example after the .title element.

Then use the created element in the ReactDOM.render call.

React 17 and below:

const reactContainer = document.createElement('div');
const target = document.querySelector('.chat .title');

target.after(reactContainer);

ReactDOM.render(Component, reactContainer);

React 18 and above:

const reactContainer = document.createElement('div');
const target = document.querySelector('.chat .title');

target.after(reactContainer);

const root = createRoot(reactContainer);
root.render(Component);
almost 3 years ago · Juan Pablo Isaza Denunciar
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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda