shadcn-ahooks

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.

Documentation and Examples

Installation

Open in
pnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useLatest.json
npx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useLatest.json
yarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useLatest.json
bun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useLatest.json

A Hook that returns the latest value, effectively avoiding the closure problem.

Examples

Basic usage

API

const latestValueRef = useLatest<T>(value: T): MutableRefObject<T>;

On this page