usePrevious()
The
usePrevious() hook stores the previous value of a state or prop. It is useful for comparing values between renders, detecting direction of changes, or triggering effects only when a value changes in a specific way.Import
typescript
Usage
Current Value0
Previous Value
-
Component.tsx
API
Arguments
value– T The value to track.
Returns
Returns the previous value of type
T | undefined. On the first render, it returns undefined.