Skip to content
KaUI is under active development. If you run into a bug, please open an issue.

Async Button

A button that performs async operations with a no-layout-shift loading state.

pnpm dlx shadcn@latest add @kaui/async-button
import { AsyncButton } from "@/components/ui/async-button";
import { addToCart } from "@/actions/cart";
import { toast } from "sonner";
<AsyncButton
action={() => addToCart({ inCart: true })}
onSuccess={() => toast.success("Added to cart!")}
onError={() => toast.error("Something went wrong.")}
>
Add to Cart
</AsyncButton>;
PropTypeDefaultDescription
action() => Promise<TData> | TDataThe async function to run on click
loadingTextReactNodechildrenContent shown inside the button while loading
onSuccess(data?: TData) => voidCalled after action resolves
onError(error?: TError) => voidCalled if action throws
onSettled() => voidCalled after either success or error

All other Button props are forwarded.