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