Ad

ComponentWillUnmount Is Not Getting Invoked

- 1 answer

I have a backbone application, where i am trying to integrate React components.

React component is mounted using following code : ReactDOM.render( <WrappedComponent />, node ); where node is the DOM mode. This way React lifecycle events like componentWillMount and componentDidMount are getting called fine.

But when routing happen through Backbone routing, and React component getting removed from DOM, componentWillUnmount is not invoked.

Any solutions ?

Ad

Answer

componentWillUnmount does not get called automatically when the container node gets removed. It only gets called:

  1. At the top level, when you call ReactDOM.unmountComponentAtNode
  2. As child components, when the parent unmounts the component
Ad
source: stackoverflow.com
Ad