When a component unmounts, use the useEffect hook to trigger a react hook. When the component unmounts, the function we return from the useEffect hook is called and can be used for cleanup.