# @react-hook/latest

> A React hook that updates useRef().current with the most recent value each invocation

Latest version **1.0.3** (published 2020-09-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install @react-hook/latest
pnpm add @react-hook/latest
yarn add @react-hook/latest
bun add @react-hook/latest
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2020-09-10 |
| First published | 2020-06-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1530 |
| Author | Jared Lunde |
| Maintainers | jaredlunde |
| Keywords | react, react component, use-ref, use-latest, use-effect-callback, useeffect callback |

## Links

- npm: https://www.npmjs.com/package/@react-hook/latest
- Repository: https://github.com/jaredLunde/react-hook
- Homepage: https://github.com/jaredLunde/react-hook/tree/master/packages/latest#readme
- Issues: https://github.com/jaredLunde/react-hook/issues
- npm.io page: https://npm.io/package/@react-hook/latest

## 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

- 1.0.3 (latest) — 2020-09-10
- 1.0.2 — 2020-06-05
- 1.0.1 — 2020-06-05
- 1.0.0 — 2020-06-05

## README

<hr>
<div align="center">
  <h1 align="center">
    useLatest()
  </h1>
</div>

<p align="center">
  <a href="https://bundlephobia.com/result?p=@react-hook/latest">
    <img alt="Bundlephobia" src="https://img.shields.io/bundlephobia/minzip/@react-hook/latest?style=for-the-badge&labelColor=24292e">
  </a>
  <a aria-label="Types" href="https://www.npmjs.com/package/@react-hook/latest">
    <img alt="Types" src="https://img.shields.io/npm/types/@react-hook/latest?style=for-the-badge&labelColor=24292e">
  </a>
  <a aria-label="Build status" href="https://travis-ci.com/jaredLunde/react-hook">
    <img alt="Build status" src="https://img.shields.io/travis/com/jaredLunde/react-hook?style=for-the-badge&labelColor=24292e">
  </a>
  <a aria-label="NPM version" href="https://www.npmjs.com/package/@react-hook/latest">
    <img alt="NPM Version" src="https://img.shields.io/npm/v/@react-hook/latest?style=for-the-badge&labelColor=24292e">
  </a>
  <a aria-label="License" href="https://jaredlunde.mit-license.org/">
    <img alt="MIT License" src="https://img.shields.io/npm/l/@react-hook/latest?style=for-the-badge&labelColor=24292e">
  </a>
</p>

<pre align="center">npm i @react-hook/latest</pre>
<hr>

A React hook that updates useRef().current with the most recent value each invocation

## Quick Start

```jsx harmony
import useLatest from '@react-hook/latest'

const useEvent = (element, name, listener) => {
  const latest = useLatest(listener)

  React.useEffect(() => {
    const listen = (e) => latest.current(e)
    element.addEventListener(name, listen)
    return () => element.removeEventListener(name, listen)
  }, [latest])
}
```

## API

### useLatest(value)

```ts
const useLatest: <T extends any>(current: T) => React.MutableRefObject<T>
```

### Props

| Prop  | Type            | Required? | Description               |
| ----- | --------------- | --------- | ------------------------- |
| value | `T extends any` | Yes       | Any value you want stored |

### Returns `React.MutableRefObject<T>`

## LICENSE

MIT

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