# use-latest-callback

> React hook which returns the latest callback without changing the reference

Latest version **0.3.5** (published 2026-07-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-latest-callback
pnpm add use-latest-callback
yarn add use-latest-callback
bun add use-latest-callback
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.3.5 |
| Published | 2026-07-26 |
| First published | 2021-06-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 45 |
| Author | Satyajit Sahoo |
| Maintainers | satya164 |
| Keywords | react, use-event, use-callback |

## Links

- npm: https://www.npmjs.com/package/use-latest-callback
- Repository: https://github.com/satya164/use-latest-callback
- Homepage: https://github.com/satya164/use-latest-callback#readme
- Issues: https://github.com/satya164/use-latest-callback/issues
- npm.io page: https://npm.io/package/use-latest-callback

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.3.5 (latest) — 2026-07-26
- 0.3.4 — 2026-05-13
- 0.3.3 — 2025-11-28
- 0.3.2 — 2025-10-29
- 0.3.1 — 2025-10-11
- 0.3.0 — 2025-10-11
- 0.2.6 — 2025-10-11
- 0.2.5 — 2025-10-06
- 0.2.4 — 2025-06-14
- 0.2.3 — 2024-11-14
- 0.2.2 — 2024-11-14
- 0.2.1 — 2024-07-10
- 0.2.0 — 2024-07-10
- 0.1.11 — 2024-07-07
- 0.1.10 — 2024-07-07
- … 9 more at https://npm.io/package/use-latest-callback/versions

## README

# use-latest-callback

React hook which returns the latest callback without changing the reference.

This is useful for scenarios such as event listeners where you may not want to resubscribe when the callback changes.

## Installation

Open a Terminal in the project root and run:

```sh
npm install use-latest-callback
```

## Usage

The `useLatestCallback` hook accepts a function as its argument and returns a function that preserves its reference across renders.

```js
import useLatestCallback from 'use-latest-callback';

// ...

function MyComponent() {
  const callback = useLatestCallback((value) => {
    console.log('Changed', value);
  });

  React.useEffect(() => {
    someEvent.addListener(callback);

    return () => someEvent.removeListener(callback);
  }, [callback]);

  return <>{/* whatever */}</>;
}
```

It's important to note that the callback is not intended to be called during the render phase. Only call the callback in response to an event.

---
_Source: https://npm.io/package/use-latest-callback · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
