useLatest
A Hook that returns the latest value, effectively avoiding the closure problem.
Overview
A Hook that returns the latest value, effectively avoiding the closure problem.
Installation
Open inpnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useLatest.jsonnpx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useLatest.jsonyarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useLatest.jsonbun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useLatest.jsonA Hook that returns the latest value, effectively avoiding the closure problem.
Examples
Basic usage
API
const latestValueRef = useLatest<T>(value: T): MutableRefObject<T>;