Open this example in the interactive library
Live preview
Source code
// components/TwoCounterTransfer.tsx
import { useState } from "react";
export default function TwoCounterTransfer({ initial = 0 }: { initial?: number } = {}) {
const [left, set] = useState(initial);
const [right, move] = useState(0);
return (
<button
disabled={left <= 0}
onClick={() => {
set((n) => n - 1);
move((n) => n + 1);
}}
>
Move one · Available {left} · Assigned {right}
</button>
);
}
