import { useEffect, useRef } from 'react'; /** * Get the previous state or prop based on the value from previous render. * * • * * @param state State (or prop). */ export function usePrevious(state: T) { const ref = useRef(); useEffect(() => { ref.current = state; }); return ref.current; }