A higher order component to make sure the react component passed as argument always unmounts properly, even if React does not have the time to call componentWillUnmount function.

unmount, unmounting, beforeunload, react, higher, order, component, hoc, graceful, react-component
npm install react-graceful-unmount@1.0.7


What is this about?

This package is about assuring that the componentWillUnmount lifecycle method always run, so if you find yourself in a situation where you expect that method to run but it is not being called this package is for you.

How does it work?

This package provides a higher order component that you can use to assure your component componentWillUnmount lifecycle method is called. It does this by hooking to the 'beforeunload' event and making the wrapped component to unmount according to this event. If you are using rails we've got you covered, this higher order component also hooks to the 'turbolinks:before-render', so your component will also unmount according to that event.


To install, you can use npm or yarn:

$ npm install react-graceful-unmount
$ yarn add react-graceful-unmount



    import withGracefulUnmount from 'react-graceful-unmount'
    import React, {Component} from 'react'
    class YourComponent extends Component {
        componentWillUnmount() {
           // This function will always be called.
           console.log('running componentWillUnmount() in YourComponent') 
        render() {
            return <div> Hello World </div>
    // This will export your component wrapped with react-graceful-unmount functionality.
    export default withGracefulUnmount(YourComponent)