- Hooks
- Browser hooks
- usePrevious
usePrevious
Track the previous value of a variable with usePrevious.
use-previous.tsx
Installation
Copy and paste the following code into your project.
use-previous.ts
Update the import paths to match your project setup.
Parameters
Name | Type | Description |
---|---|---|
newValue | any | The new value to track and return the previous of. |
Return value
Name | Type | Description |
---|---|---|
previousValue | any | The previous value of the provided newValue. |