Custom hook to get the previous value of a state or prop.
This hook returns the value from the previous render.
The current value to track.
const [count, setCount] = useState(0);const prevCount = usePrevious(count);useEffect(() => { console.log('Current count:', count); console.log('Previous count:', prevCount);}, [count]); Copy
const [count, setCount] = useState(0);const prevCount = usePrevious(count);useEffect(() => { console.log('Current count:', count); console.log('Previous count:', prevCount);}, [count]);
Custom hook to get the previous value of a state or prop.
This hook returns the value from the previous render.