# Async action button with loading and success states

> Async action button with loading and success states

A shadcn/ui block from the [@reui](https://reui.io) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/reui/c-button-44).

- Page, with a live preview: https://shadcn.exchange/r/reui/c-button-44
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/reui/c-button-44-light-aabde022021b01ff.png
- Registry item: https://reui.io/r/new-york-v4/c-button-44.json
- Listed: 2026-10-13, source last changed 2026-10-13

## Install

```bash
npx shadcn@latest add https://reui.io/r/new-york-v4/c-button-44.json
```

Run it in a project that has shadcn/ui set up. It adds the files below and installs what they depend on.

## Dependencies

- Registry items: `button`, `spinner`

## Files

### `c-button-44.tsx`

```tsx
"use client"

import { useEffect, useState } from "react"

import { Button } from "@/components/ui/button"
import { Spinner } from "@/components/ui/spinner"
import { IconPlaceholder } from "@/app/(create)/components/icon-placeholder"

type Status = "idle" | "loading" | "success"

export function Pattern() {
  const [status, setStatus] = useState<Status>("idle")

  useEffect(() => {
    if (status !== "success") return

    const timer = setTimeout(() => setStatus("idle"), 2000)
    return () => clearTimeout(timer)
  }, [status])

  return (
    <Button
      onClick={() => {
        if (status !== "idle") return

        setStatus("loading")
        setTimeout(() => setStatus("success"), 900)
      }}
      disabled={status === "loading"}
      aria-busy={status === "loading"}
      aria-live="polite"
      className="min-w-32"
    >
      {status === "loading" ? (
        <>
          <Spinner aria-hidden="true" />
          Saving…
        </>
      ) : status === "success" ? (
        <>
          <IconPlaceholder
            lucide="CheckIcon"
            tabler="IconCheck"
            hugeicons="Tick02Icon"
            phosphor="CheckIcon"
            remixicon="RiCheckLine"
            aria-hidden="true"
          />
          Saved
        </>
      ) : (
        "Save changes"
      )}
    </Button>
  )
}
```
