import { useRef, useEffect } from 'react'; /** * A custom React hook to get the previous value of a prop or state. * @param {any} value - The current value to track. * @returns {any} The previous value. */ function usePrevious(value) { const ref = useRef(); useEffect(() => { ref.current = value; }, [value]); return ref.current; }