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

169
Visualizações
Add a react component for each querySelectorAll() that is found?

I need a way to add my react component to the screen, for each place they find the id "#card".

const container = document.querySelectorAll('#card');

ReaactDOM.render(<App />, container);

The code above doesn't render anything on the page. With the error: Uncoaught Error: Target container is not a DOM element. I've researched and found that querySelectorAll only returns a NodeList that I need to loop. However, all attempts I've tried aren't working.

Not sure if quuerySelectorAll is the right choice. Or if I need to fix how I'm calling it.

const App = () => {
  return (
    <div class="card_container">
        {console.log(cards)}
        {cards.map() => {
                <div>{cardNumber}</div>
        }

    </div>
  );
};

for (const el of document.querySelectorAll(".react-container")) {
  ReactDOM.render(<App/>, el);
}

[Stack 1]
[Stack 2]
[Stack 2]
[Stack 3]
[Stack 3]
[Stack 3]
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to actually iterate the array that querySelectorAll returns. You should also never duplicate id within a page.

const App = () => {
  return (
    <div>I'm a React app!</div>
  );
};

for (const el of document.querySelectorAll(".react-container")) {
  ReactDOM.render(<App/>, el);
}
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>

<div class="react-container"></div>
<div class="react-container"></div>
<div class="react-container"></div>
<div class="react-container"></div>

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