shadcn-ahooks

useRafState

Update the state in [requestAnimationFrame](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame) callback, generally used for performance optimization.

Overview

Update the state in requestAnimationFrame callback, generally used for performance optimization.

Documentation and Examples

Installation

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

Update the state in requestAnimationFrame callback, generally used for performance optimization.

Examples

Default usage

API

Same as React.useState.

On this page