Skip to content

useLatest ​

Hook that returns the stable reference of the value

utilities
test coverage
Last changed: 1 minute ago

Installation ​

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

Usage ​

typescript
const { value, ref } = useLatest(value);

Demo ​

Api ​

Parameters

NameTypeDefaultNote
valueValue-The value to get the previous value

Returns

UseLatestReturn<Value>

Type declaration ​

typescript
import type { RefObject } from 'react';

export interface UseLatestReturn<Value> {
  ref: RefObject<Value>;
  value: Value;
}

Source ​

Source • Demo

Contributors ​

D
debabin
debabin

Released under the MIT License.