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

168
Visualizações
How to call child1(class component) method from child2(class component) via a parent(functional component) in React JS (V 2015)?

I am using React version less than 16. So, cannot use hooks or redux (any 3rd party tools) in this app.

I have a parent (functional component) having two child (class) components. I need to execute child1's submit(event) method from a button click inside child2 . Kindly help me with a working logic for this.

Edit: This is the real life scenario: There is a parent functional component which has 2 class child components (C1 and C2). I have a C1 class component on left side of screen and C2 class component on right side. In C1, i select some input value and click on "submit" to get some data (upon API call) to be shown on the C2. Now, requirement is : After data got loaded in C2, if i change some inputs in C1 and then click on a "check" button inside C2, the "submit" of C1 should get fired with the latest selected inputs (i.e. the API in C1 will get called with latest inputs).

Below is the skeleton of a simple app structure of the real life app:

parent:

export default function Parent() {
 return (
        <div>
            <C1 />
            <C2 />
        </div>
    );
}

child1:

class C1 extends React.Component{
    constructor(props) {
        super(props);
        this.state = {}
    }
    
    submitC1(event) {
        //do something with event.target by invoking from child2
    }
    
    render() {
        return (
            <div>
                <form onSubmit={this.submitC1.bind(this)}>
                    <input type="text" />
                    <button type="submit">Submit</button>
                </form>
            </div>
        );
    }
}

child2:

class C2 extends React.Component{
    constructor(props) {
        super(props);
        this.state = {}
    }

    render() {
        return (
            <div>
                <button onClick={/*invoke child1 submit method with the event from child1 button itself*/}>Check</button>
            </div>
        );
    }
}

export default C2;

Edit : still looking for answers and it's not a duplicate.

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