How to manage componentWillUnmount with useEffect
If you add a return function inside the useEffect function, it is triggered when a component unmounts from the DOM. This looks like:
import React, { useEffect } from 'react';
const ComponentExample => () => {
useEffect(() => {
return () => {
// Anything in here is fired on component unmount.
}
}, [])
}