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

179
Vistas
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 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