Skip to Content
⭐️ Leave a star →
HooksusePrevious

usePrevious

Tracks the value from the previous render / tracked update. Returns undefined on the first run.

import { useEffect } from 'react' import { usePrevious } from '@wire-ui/react' function Counter({ count }: { count: number }) { const previous = usePrevious(count) useEffect(() => { if (previous !== undefined && count > previous) { console.log(`went up by ${count - previous}`) } }, [count, previous]) return <span>{count}</span> }

Parameters

ParamTypeDescription
valueTValue to track.

Returns

T | undefined — the value from the previous render, or undefined before the first update.
Last updated on

MIT License © 2026 wire-ui

usePrevious – Wire UI