October 2019
Intermediate to advanced
426 pages
11h 49m
English
The useOnUnmount Hook has a similar effect to the componentWillUnmount life cycle. It is used as follows:
import React from 'react'import { useOnUnmount } from 'react-hookedup'export default function UseOnUnmount () { useOnUnmount(() => console.log('unmounting')) return <div>click the "unmount" button above and look at the console</div>}
The preceding code will output unmounting to the console when the component gets unmounted (before the React component is removed from the DOM).
If you remember from Chapter 4, Using the Reducer and Effect Hooks, we can return a cleanup function from the useEffect Hook, which will be called when the component unmounts. This means that we could alternatively implement the useOnMount
Read now
Unlock full access