Skip to content

usePrevious ​

Hook that returns the previous value

utilities
test coverage
Last changed: last month

Installation ​

Library
CLI
Manual
typescript
import { usePrevious } from '@siberiacancode/reactuse';

Usage ​

typescript
const prevValue = usePrevious(value);

Demo ​

Api ​

Parameters

NameTypeDefaultNote
valueValue-The value to get the previous value
options.equality?(a: Value, b: Value) => boolean-The custom equality function to determine if the value has changed

Returns

Value | undefined

Type declaration ​

typescript
export interface UsePreviousOptions<Value> {
  equality: (a: Value, b: Value) => boolean;
}

Source ​

Source • Demo

Contributors ​

D
debabin
debabin
B
babin
babin
H
hywax
hywax

Released under the MIT License.