import { useEffect, useRef } from 'react'; const usePrevious = (state: T): T | undefined => { const ref = useRef(); useEffect(() => { ref.current = state; }); return ref.current; }; export default usePrevious;