Skip to content

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 ​

Source · Document · Demo

Released under the MIT License.