VisorVisor
Hooks

usePrevious

Returns the previous value of a variable from the last render.

Usage

const prevCount = usePrevious(count)
const direction = count > (prevCount ?? 0) ? "up" : "down"

Installation

npx visor add use-previous

Parameters

NameTypeRequiredDefaultDescription
valueTYes--The value to track across renders.

Returns

NameTypeDescription
previousValueT | undefinedThe value from the previous render, or undefined on the first render.