# preact-pair

> 🖇️ Util to help with the paired hook pattern

Latest version **1.1.15** (published 2025-01-02) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install preact-pair
pnpm add preact-pair
yarn add preact-pair
bun add preact-pair
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.15 |
| Published | 2025-01-02 |
| First published | 2022-05-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=23 |
| Dependencies | 1 |
| Unpacked size | 9.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Lou Cyx |
| Maintainers | loucyx |
| Keywords | hooks, lou.codes, loucyx, pair, preact, tsx, typescript |

## Links

- npm: https://www.npmjs.com/package/preact-pair
- Repository: https://github.com/loucyx/lou.codes
- Homepage: https://lou.codes/libraries/preact_pair/
- Issues: https://github.com/loucyx/lou.codes/issues
- npm.io page: https://npm.io/package/preact-pair

## Dependencies (1)

- [@lou.codes/types](https://npm.io/package/@lou.codes/types.md) 4.0.5

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.1.15 (latest) — 2025-01-02
- 1.1.14 — 2024-06-16
- 1.1.13 — 2024-06-12
- 1.1.12 — 2024-06-12
- 1.1.11 — 2024-05-28
- 1.1.10 — 2024-05-23
- 1.1.9 — 2024-05-21
- 1.1.8 — 2024-05-21
- 1.1.6 — 2024-05-02
- 1.1.5 — 2024-04-19
- 1.1.4 — 2024-04-17
- 1.1.3 — 2024-04-12
- 1.1.1 — 2024-04-11
- 1.1.0 — 2024-04-06
- 1.0.82 — 2024-04-05
- … 81 more at https://npm.io/package/preact-pair/versions

## README

<img id="logo" alt="preact-pair" src="https://lou.codes/logos/preact_pair.svg" height="128" />

![Coverage][coverage-badge] ![License][license-badge]
![NPM Version][npm-version-badge] ![Open Issues][open-issues-badge]
![Size][size-badge]

🖇️ Util to help with the [paired hook pattern][article].

## Usage

### 📦 Node

Install `preact-pair` as a dependency:

```bash
pnpm add preact-pair
# or
npm install preact-pair
# or
yarn add preact-pair
```

Import it and use it:

```tsx
import { useState } from "preact";
import { pair } from "preact-pair";

const useCount = initialCount => {
	const [count, setCount] = useState(initialCount);

	return { onClick: () => setCount(count + 1), children: count };
};

const PairedCount = pair(useCount);

const Component = ({ array = [] }) => (
	<ul>
		{array.map(key => (
			<PairedCount key={key}>
				{usePairedCount => {
					const props = usePairedCount(key);

					return (
						<li>
							<button type="button" {...props} />
						</li>
					);
				}}
			</PairedCount>
		))}
	</ul>
);
```

### 🦕 Deno

Import `preact-pair` using the `npm:` prefix, and use it directly:

```tsx
import { useState } from "npm:preact";
import { pair } from "npm:preact-pair";

const useCount = initialCount => {
	const [count, setCount] = useState(initialCount);

	return { onClick: () => setCount(count + 1), children: count };
};

const PairedCount = pair(useCount);

const Component = ({ array = [] }) => (
	<ul>
		{array.map(key => (
			<PairedCount key={key}>
				{usePairedCount => {
					const props = usePairedCount(key);

					return (
						<li>
							<button type="button" {...props} />
						</li>
					);
				}}
			</PairedCount>
		))}
	</ul>
);
```

### 🌎 Browser

Import `preact-pair` using [esm.sh][esm.sh], and use it directly:

```html
<script type="module">
	import { h, useState } from "https://esm.sh/preact";
	import { pair } from "https://esm.sh/preact-pair";

	const useCount = initialCount => {
		const [count, setCount] = useState(initialCount);

		return { onClick: () => setCount(count + 1), children: count };
	};

	const PairedCount = pair(useCount);

	const Component = ({ array = [] }) =>
		h("ul", {
			children: array.map(key =>
				h(PairedCount, {
					key,
					children: usePairedCount => {
						const props = usePairedCount(key);

						return h("li", { children: h("button", props) });
					},
				}),
			),
		});
</script>
```

## Useful links

-   📝 [Documentation][documentation]: TypeDoc generated documentation.
-   ⏳ [Changelog][changelog]: List of changes between versions.
-   ✅ [Tests Coverage][coverage]: Coveralls page with tests coverage.

<!-- Reference -->

[article]: https://lou.cx/articles/the-paired-hook-pattern
[changelog]:
	https://github.com/loucyx/lou.codes/blob/main/packages/preact-pair/CHANGELOG.md
[coverage-badge]:
	https://img.shields.io/coveralls/github/loucyx/lou.codes.svg?label=Test+Coverage&labelColor=666&color=0a8
[coverage]: https://coveralls.io/github/loucyx/lou.codes
[documentation]: https://lou.codes/libraries/preact_pair/
[esm.sh]: https://esm.sh
[license-badge]:
	https://img.shields.io/npm/l/preact-pair.svg?label=License&labelColor=666&color=0a8
[npm-version-badge]:
	https://img.shields.io/npm/v/preact-pair.svg?label=NPM+Version&labelColor=666&color=0a8
[open-issues-badge]:
	https://img.shields.io/github/issues/loucyx/lou.codes.svg?label=Issues&labelColor=666&color=0a8
[size-badge]:
	https://img.shields.io/badge/dynamic/json?label=Bundle+Size&labelColor=666&color=0a8&suffix=KiB&query=%24.size&url=https%3A%2F%2Fraw.githubusercontent.com%2Floucyx%2Flou.codes%2Fmain%2Fpackages%2Fpreact-pair%2Fpackage.json

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