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

92
Vistas
React component no reacting when a div tag is added below it

I have two components that I want to add to a webpage. The first component works fine when is the only component in index.html, but when I add the div with id="disp" the components stop responding. I have not idea of why is this behavior.

Here is how my index.html looks like:

  <body>
  <div id="input"></div>
  <script type="text/JavaScript" src="./index.js"></script>

  <div id="disp"></div>
  <script type="text/JavaScript" src="./index.js"></script>

  </body>

And my index.js:

import React from 'react';
import ReactDOM from 'react-dom';
import Input from './components/input';
import Display from './components/display';

ReactDOM.render(
  <React.StrictMode>
  <Input />
  </React.StrictMode>,
  document.getElementById('input')
);

ReactDOM.render(
  <React.StrictMode>
  <Display />
  </React.StrictMode>,
  document.getElementById('disp')
);
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can only have one root element at React. You can handle it like this:

ReactDOM.render(
  <React.StrictMode>
  <>
    <Input />
    <Display />
  </>
  </React.StrictMode>,
  document.getElementById('root')
);

And:

<body>
<div id="root">
  <div id="input"></div>
  <div id="disp"></div>
</div>
  <script type="text/JavaScript" src="./index.js"></script>
</body>

Basically, I wrapped those two elements using a div with root id.

about 4 years ago · Santiago Trujillo 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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda