usePrevious
A Hook to return the previous state.
Overview
A Hook to return the previous state.
Installation
Open inpnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/usePrevious.jsonnpx shadcn@latest add https://shadcn-ahooks.vercel.app/r/usePrevious.jsonyarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/usePrevious.jsonbun shadcn@latest add https://shadcn-ahooks.vercel.app/r/usePrevious.jsonA Hook to return the previous state.
Examples
Default usage
Custom shouldUpdate function
API
const previousState: T = usePrevious<T>(
state: T,
shouldUpdate?: (prev: T | undefined, next: T) => boolean
);Result
| Property | Description | Type |
| - | | - |
| state | The state that needs to be tracked | T | - |
| shouldUpdate | Optional. Customize whether the state value should be updated | (prev: T \| undefined, next: T) => boolean | (a, b) => !Object.is(a, b) |
usePagination
usePagination is implemented based on useRequest and encapsulates common paging logic. The differences from useRequest are as follows.
useRafInterval
A hook implements with requestAnimationFrame for better performance. The API is consistent with useInterval, the advantage is that the execution of the timer can be stopped when the page is not rendering, such as page hiding or minimization.