usePrevious
이전 렌더링에서 인수의 값을 반환하는 커스텀 훅입니다.
Code
Interface
typescript
const usePrevious: <T>(value: T) => T;
Usage
typescript
import { useState } from 'react';
import { usePrevious } from '@modern-kit/react';
const Example = () => {
const [count, setCount] = useState(0);
const previousCount = usePrevious(count);
const onIncrementCount = () => {
setCount(count + 1);
};
return (
<div>
<div>Current Count is - {count}</div>
<div>Previous Count is - {previousCount}</div>
<button onClick={onIncrementCount}>Increment</button>
</div>
);
};
Current Count is - 0
Previous Count is - 0