Skip to Content
ohooks

usePreviousDistinct

Returns the most recent distinct value prior to the current value.

Loading preview...

The usePreviousDistinct hook tracks and returns the last value that was not equal to the current value (using Object.is by default or a custom comparator), ignoring re-renders where the value stayed the same.

Installation

pnpm dlx shadcn@latest add https://ohooks.vercel.app/r/usePreviousDistinct.json

Usage