"use client"; import { useEffect, useRef, useState, type ReactNode } from "react"; import { Button, type ButtonProps } from "../ui/Button.tsx"; /** State follows the supplied promise. AbortSignal allows consumers to cancel network work. */ export function AsyncButton({ action, children, successLabel = "Done", onError, ...props }: Omit & { action: (signal: AbortSignal) => Promise; children: ReactNode; successLabel?: string; onError?: (error: unknown) => void; }) { const [state, setState] = useState<"idle" | "pending" | "success" | "error">( "idle", ); const controller = useRef(null), running = useRef(false); useEffect(() => () => controller.current?.abort(), []); return ( {state === "error" ? "Action failed. Try again." : ""} ); }