4.0.10 ā€¢ Published 8 days ago

react-pair v4.0.10

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

Coverage License NPM Version Open Issues Size

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

Usage

šŸ“¦ Node

Install react-pair as a dependency:

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

Import it and use it:

import { useState } from "react";
import { pair } from "react-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 react-pair using the npm: prefix, and use it directly:

import { useState } from "npm:react";
import { pair } from "npm:react-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 react-pair using esm.sh, and use it directly:

<script type="module">
	import { createElement, useState } from "https://esm.sh/react";
	import { pair } from "https://esm.sh/react-pair";

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

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

	const PairedCount = pair(useCount);

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

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

Useful links

4.0.10

8 days ago

4.0.9

19 days ago

4.0.8

24 days ago

4.0.7

29 days ago

4.0.6

1 month ago

4.0.5

1 month ago

4.0.4

1 month ago

4.0.3

1 month ago

4.0.1

1 month ago

3.0.97

2 months ago

4.0.0

1 month ago

3.0.96

2 months ago

3.0.95

2 months ago

3.0.94

2 months ago

3.0.93

2 months ago

3.0.92

2 months ago

3.0.91

2 months ago

3.0.89

2 months ago

3.0.90

2 months ago

3.0.88

2 months ago

3.0.87

3 months ago

3.0.86

3 months ago

3.0.85

3 months ago

3.0.84

3 months ago

3.0.83

4 months ago

3.0.82

4 months ago

3.0.81

4 months ago

3.0.80

4 months ago

3.0.79

4 months ago

3.0.78

4 months ago

3.0.77

5 months ago

3.0.76

5 months ago

3.0.74

5 months ago

3.0.75

5 months ago

3.0.73

5 months ago

3.0.68

5 months ago

3.0.69

5 months ago

3.0.70

5 months ago

3.0.71

5 months ago

3.0.72

5 months ago

3.0.67

5 months ago

3.0.66

5 months ago

3.0.56

7 months ago

3.0.57

7 months ago

3.0.54

8 months ago

3.0.55

7 months ago

3.0.58

7 months ago

3.0.59

7 months ago

3.0.52

8 months ago

3.0.53

8 months ago

3.0.50

8 months ago

3.0.51

8 months ago

3.0.65

6 months ago

3.0.60

6 months ago

3.0.63

6 months ago

3.0.64

6 months ago

3.0.61

6 months ago

3.0.62

6 months ago

3.0.46

8 months ago

3.0.47

8 months ago

3.0.48

8 months ago

3.0.45

8 months ago

3.0.43

8 months ago

3.0.44

8 months ago

3.0.41

8 months ago

3.0.42

8 months ago

3.0.40

8 months ago

3.0.28

12 months ago

3.0.34

10 months ago

3.0.35

10 months ago

3.0.32

10 months ago

3.0.33

10 months ago

3.0.38

9 months ago

3.0.39

9 months ago

3.0.36

9 months ago

3.0.37

9 months ago

3.0.30

11 months ago

3.0.31

11 months ago

3.0.29

12 months ago

3.0.23

1 year ago

3.0.24

1 year ago

3.0.21

1 year ago

3.0.22

1 year ago

3.0.27

1 year ago

3.0.25

1 year ago

3.0.26

1 year ago

3.0.20

1 year ago

3.0.18

1 year ago

3.0.19

1 year ago

3.0.13

1 year ago

3.0.16

1 year ago

3.0.17

1 year ago

3.0.14

1 year ago

3.0.15

1 year ago

3.0.12

1 year ago

3.0.10

2 years ago

3.0.11

1 year ago

3.0.8

2 years ago

3.0.9

2 years ago

3.0.4

2 years ago

3.0.3

2 years ago

3.0.7

2 years ago

3.0.6

2 years ago

3.0.5

2 years ago

3.0.2

2 years ago

2.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.0.1

2 years ago

2.0.0

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