# react-node-key

> Automatic key-marked for React nodes, generate an unique identifier by render location

Latest version **0.4.0** (published 2022-05-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-node-key
pnpm add react-node-key
yarn add react-node-key
bun add react-node-key
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2022-05-20 |
| First published | 2020-03-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 40.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | CJY0208 |
| Maintainers | cjy0208 |
| Keywords | node key, unique, react node key, file key, identifier, react keep alive, react activation |

## Links

- npm: https://www.npmjs.com/package/react-node-key
- Repository: https://github.com/CJY0208/react-node-key
- npm.io page: https://npm.io/package/react-node-key

## Dependencies (2)

- [szfe-tools](https://npm.io/package/szfe-tools.md) ^0.0.0-beta.7
- [jsx-ast-utils](https://npm.io/package/jsx-ast-utils.md) ^2.2.1

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.4.0 (latest) — 2022-05-20
- 0.3.2 — 2022-03-22
- 0.3.1 — 2021-12-08
- 0.3.0 — 2021-04-26
- 0.2.0 — 2020-11-29
- 0.1.8 — 2020-11-03
- 0.1.7 — 2020-06-30
- 0.1.6 — 2020-06-29
- 0.1.5 — 2020-06-29
- 0.1.3 — 2020-06-29
- 0.1.2 — 2020-06-28
- 0.1.1 — 2020-06-28
- 0.1.0 — 2020-06-28
- 0.0.4 — 2020-03-23
- 0.0.3 — 2020-03-22
- … 2 more at https://npm.io/package/react-node-key/versions

## README

# React Node Key

[![size](https://img.shields.io/bundlephobia/minzip/react-node-key.svg)](https://github.com/CJY0208/react-node-key)
[![dm](https://img.shields.io/npm/dm/react-node-key.svg)](https://github.com/CJY0208/react-node-key)

English | [中文说明](./README_CN.md)

Automatic key-marked for React nodes, generate an unique identifier by render location

---

## Compatibility

- React v16+

- Preact v10+

---

## Install

```bash
yarn add react-node-key
# or
npm install react-node-key
```

---

## Usage

#### 1. Add `react-node-key/babel` plugins in `.babelrc`

[Why is it needed?](https://github.com/CJY0208/react-activation/issues/18#issuecomment-564360695)

The plugin adds a `_nk` attribute to each JSX element during compilation to help the `react-node-key` runtime **generate an unique identifier by render location**.

```javascript
{
  "plugins": [
    "react-node-key/babel"
  ]
}
```

#### 2. Use `<NodeKey>` as your component's wrapper

```javascript
import React from 'react'
import ReactDOM from 'react-dom'
import NodeKey from 'react-node-key'

import Test from './Test'

ReactDOM.render(
  <NodeKey>{nodeKey => <Test key={nodeKey} />}</NodeKey>,
  document.getElementById('root')
)
```

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