Options
All
  • Public
  • Public/Protected
  • All
Menu

react-pair

Vangware's React Pair

Build Status Coverage License NPM Version Open Issues

🖇️ Util to help with the paired hook pattern.

Installation

Direct usage

For envs like Deno or the browser:

import { pair } from "https://esm.sh/react-pair";

Local installation

For Node:

npm i react-pair

Usage

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>
);

React DevTools integration

React DevTools screenshot

Documentation

Documentation can be found HERE. It is auto-generated with typedoc based on the JSDocs and the types in the source. Shouldn't be necessary to read this, code editors like VSCode integrate the documentation in the UI.

Changelog

Changelog can be found HERE.