usePrevious
Importing usePrevious Hook​
import { usePrevious } from '@ciceksepeti/cui-hooks';
Example​
import React, { useState } from 'react';
import { usePrevious } from '@ciceksepeti/cui-hooks';
export const Example = () => {
const [count, setCount] = useState(0);
const previousValue = usePrevious(count);
return (
<div>
<span>Previous Value: {previousValue}</span>
<span>Value: {count}</span>
<button onClick={() => setCount(count + 1)}>Update Value</button>
</div>
);
};
Preview & Test​
PREVIEW & TEST AREA
usePrevious
- Holds and returns the previous value of a state.
Previous Value: Value: 0