Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!