🖇️ Util to help with the paired hook pattern.
For envs like Deno or the browser:
import { pair } from "https://esm.sh/react-pair";
For Node:
npm i react-pair
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>
);
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 can be found HERE.