Skip to content
usefy

usePrevious

Lifecycle & refs

Returns the previous distinct value (the value from the last render it changed)

Install

$ npm install @usefy/use-previous

Quick start

usePrevious.tsx
import { usePrevious } from "@usefy/use-previous";

const [count, setCount] = useState(0);
const prev = usePrevious(count); // undefined, then the previous value

API reference

usePrevious<T>(value, isEqual?): T | undefined — tracks the previous distinct value; pass isEqual (defaults to Object.is) to ignore new-but-equal values.

Go deeper

This page is the quick reference. For every example, prop, and edge case, read the full README — or open Storybook to change props live.

More in lifecycle & refs