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

180
Vistas
Since componentWillUnmount is now considered legacy, what would be a way to notify a parent component when a child component is unmounted?

Since componentWillUnmount is now a legacy lifecycle method in React v17, what would be a good way to notify a parent component when it's child component is unmounted?

My thinking and from previous answers a possible approach would be to pass a function as a callback prop from the parent to the child component, but where in the child component would the callback prop then be called? In one of the lifecycle methods?

Parent component

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

childUnmounted(){
console.log('child unmounted')
}

  render() {
    return (
      <div>
        <Child unmounted={this.childUnmounted}/>
      </div>
    );
  }
}

child component

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

unmounted(){
this.props.childUnmounted()
}

  render() {
    return (
      <div>
        <p>Child component<p>
      </div>
    );
  }
}
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