1.1.6 ā€¢ Published 10 days ago

preact-pair v1.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
10 days ago

Coverage License NPM Version Open Issues Size

šŸ–‡ļø Util to help with the paired hook pattern.

Usage

šŸ“¦ Node

Install preact-pair as a dependency:

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

Import it and use it:

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:

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, and use it directly:

<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

1.1.6

10 days ago

1.1.5

23 days ago

1.1.4

25 days ago

1.1.3

29 days ago

1.1.1

1 month ago

1.1.0

1 month ago

1.0.82

1 month ago

1.0.80

1 month ago

1.0.81

1 month ago

1.0.79

1 month ago

1.0.78

2 months ago

1.0.77

2 months ago

1.0.76

3 months ago

1.0.75

3 months ago

1.0.74

3 months ago

1.0.73

4 months ago

1.0.72

4 months ago

1.0.71

4 months ago

1.0.70

4 months ago

1.0.69

4 months ago

1.0.68

4 months ago

1.0.66

5 months ago

1.0.65

5 months ago

1.0.64

5 months ago

1.0.63

5 months ago

1.0.67

5 months ago

1.0.62

5 months ago

1.0.61

6 months ago

1.0.60

6 months ago

1.0.49

7 months ago

1.0.51

7 months ago

1.0.50

7 months ago

1.0.55

7 months ago

1.0.54

7 months ago

1.0.53

7 months ago

1.0.52

7 months ago

1.0.59

6 months ago

1.0.58

6 months ago

1.0.57

6 months ago

1.0.56

6 months ago

1.0.40

8 months ago

1.0.44

8 months ago

1.0.43

8 months ago

1.0.42

8 months ago

1.0.41

8 months ago

1.0.47

8 months ago

1.0.46

8 months ago

1.0.45

8 months ago

1.0.39

8 months ago

1.0.38

8 months ago

1.0.29

11 months ago

1.0.28

12 months ago

1.0.33

10 months ago

1.0.32

10 months ago

1.0.31

10 months ago

1.0.30

10 months ago

1.0.37

8 months ago

1.0.36

9 months ago

1.0.35

9 months ago

1.0.34

10 months ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.27

12 months ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.20

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.11

1 year ago

1.0.10

2 years ago

1.0.12

1 year ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago