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

148
Visualizações
Getting the child element id from parent and rendering the button in the id in parent component react js

I have one parent component and child component. I have to get the id from child in parent component and place button in the parent component using ReactDom.render(somebutton, Id_of_the_child).

This one I have written in the component did update. But it's not working. Can anyone help me with this why this isn't working? Not able to get the child id in parent itself.

Index.js:

import React, { Component } from "react";

class parentComponent extends Component {
    constructor(props) {
         super(props); 
    }

    onClick = () =>{
         console.log("some functionality is done")
    }

    componentDidMount(){
        if(document.getElementById("child_place_holder")){
             ReactDOM.render(< button onClick={this.onClick} 
        />,$("#child_place_holder")[0]);

        }
    }

    render() {
        return (
          <div>
             <ChildComponent/>
          </div>
        );
    }
}

export default parentComponent;

ChildComponent.js:

import React, { Component } from "react";

class ChildComponent extends Component {
   constructor(props) {
       super(props);  
   }

   componentDidMount(){}
  
   render() {
      return (
        <div>
          <span id = "child_place_holder"> </span>
        </div>    
      );
   }
}
about 4 years ago · Juan Pablo Isaza
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