Skip to content

useLatest

Hook that returns the stable reference of the value

utilities
medium
test coverage
Last changed: 7 months 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

SourceDemo

Contributors

D
debabin
debabin

Released under the MIT License.