import React , { useState , useEffect } from 'react' ; interface IProps { onUnmount : ( duration : number ) => void ; children ? : React . ReactNode ; } export function TimeMounted ( props ) { const [ startTime ] = useState ( new Date ( ) ) ; const { onUnmount } = props ; useEffect ( ( ) => { return ( ) => onUnmount ( new Date ( ) . getTime ( ) - startTime . getTime ( ) ) ; } , [ startTime ] ) ; return < > { props . children } < />; }