Skip to content
On this page

usePrevious

A Hook to return the previous state.

Basic usage

Custom shouldUpdate function

Result

PropertyDescriptionType
previousRefThe previous valueReadonly<Ref<T>>

Params

PropertyDescriptionTypeDefault Value
currentRefThe state that needs to be trackedRef<T> | ComputedRef<T>-
shouldUpdateOptional. Customize whether the state value should be updated(prev: T | undefined, next: T) => boolean(a, b) => a !== b

Source

SourceDocsDemo