Version: Next

use-will-unmount

About#

componentWillUnmount lifecycle as hook for React.


Installation#

npm install --save @rooks/use-will-unmount

Importing the hook#

import useWillUnmount from "@rooks/use-will-unmount"

Usage#

function Message(){
useWillUnmount(function () {
alert("unmounted")
})
return <p> Message </p>
}
function Demo() {
const [
value,
changeValue
] = useState(true);
function toggleValue(){
changeValue(!value)
}
return <>
<p><button onClick={toggleValue}>Toggle show </button></p>
{value && <Message/>}
</>;
}
render(<Demo/>)

Arguments#

ArgumentsTypeDescriptionDefault value
callbackfunctionCallback function which needs to run on unmountundefined

A React hook for componentWillUnmount lifecycle method.#

Join Bhargav's discord server#

You can click on the floating discord icon at the bottom right of the screen and talk to us in our server.

Last updated on by imbhargav5