import { useEffect, useRef } from 'react'; function usePrevious(value) { const ref = useRef(); useEffect(() => { ref.current = value; }, [value]); return ref.current; } // Example Usage: // function Counter() { // const [count, setCount] = useState(0); // const prevCount = usePrevious(count); // return ( //
Current: {count}
//Previous: {prevCount}
// //