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

116
Vistas
Executing two functions (passed in props) sequentially in React

I have two React class components. Component1 is the parent of Component2 and I have two functions (functionA and B) that are passed in props from Component1 to Component2. Nested in Component2 I have a function, saveAndNotify(), that is supposed to execute functionA and then functionB only when functionA has finished executing completely.

For more context, functionA changes a state in Component1 and functionB takes that state to perform other functions.

See in code of Component2 below

export default class Component2 extends React.Component {
  static.propTypes = {
    functionA: PropTypes.func,
    functionB: PropTypes.func
  }


  render() {//some code
    return(//some code)
  }
  
  saveAndNotify = (my_arguments) => {
    this.props.functionA(func_a_args);
    this.props.functionB(func_b_args); // this needs to execute after functionA has 
    finished
  }

}

I'm new to JS and have read about using callbacks but I haven't been able to do this sequentially. Especially since I'm not getting how to access the react class Component with the keyword this when I'm nesting functions while using callbacks.

I'd appreciate your guidance.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You don't need a callback. Passing 2 props will make things harder to maintain, the best thing is to pass one function we can call it functionC that will use functionA and functionB, the functionA will update the state and will return it to be used by functionB.

Component2:

export default class Component2 extends React.Component {
  static.propTypes = {
    functionC: PropTypes.func,
  }


  render() {//some code
    return(//some code)
  }
  
  saveAndNotify = (my_arguments) => {
    this.props.functionC(my_arguments)
  }

}

functionC of Component1:

functionC(my_arguments)) {
  const state = this.functionA()
  this.functionB(state)
}
about 4 years ago · Juan Pablo Isaza 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