# Button: Controlled loading

> Set `loading` yourself when the work is tracked elsewhere. The button stays focusable and announces that it is busy.

Example: https://hextaui.com/docs/button/examples/controlled-loading
Component docs: https://hextaui.com/docs/button.md

## Add this example

```bash
npx shadcn@latest add https://hextaui.com/r/button-controlled-loading.json
```

This adds `components/examples/button/controlled-loading.tsx` with the Button component and the HextaUI theme tokens.

## Source

```tsx title="components/examples/button/controlled-loading.tsx"
"use client"

import * as React from "react"
import { IconSend } from "@tabler/icons-react"

import { Button } from "@/components/ui/button"

export function ButtonControlledLoading() {
  const [loading, setLoading] = React.useState(false)

  return (
    <div className="flex flex-wrap items-center justify-center gap-2">
      <Button loading={loading} onClick={() => setLoading(true)}>
        <IconSend data-icon="inline-start" />
        Send invite
      </Button>
      <Button variant="ghost" onClick={() => setLoading(false)}>
        Stop loading
      </Button>
    </div>
  )
}
```

## Props in this example

### Button

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `variant` | `"default" \| "outline" \| "secondary" \| "ghost" \| "ghost-destructive" \| "destructive" \| "link"` | `"default"` |  |
| `onClick` | `(event) => unknown` | – | Return a promise to drive feedback. |
| `loading` | `boolean` | – | Controlled loading state. |

## More Button examples

- [Variants](https://hextaui.com/docs/button/examples/variants.md)
- [Sizes](https://hextaui.com/docs/button/examples/sizes.md)
- [Pill](https://hextaui.com/docs/button/examples/pill.md)
- [With icon](https://hextaui.com/docs/button/examples/with-icon.md)
- [Disabled](https://hextaui.com/docs/button/examples/disabled.md)
- [Custom labels](https://hextaui.com/docs/button/examples/custom-labels.md)
- [Smooth width](https://hextaui.com/docs/button/examples/smooth-width.md)
- [Error details](https://hextaui.com/docs/button/examples/error-details.md)
- [Forms](https://hextaui.com/docs/button/examples/form.md)
- [Icon buttons](https://hextaui.com/docs/button/examples/icon-feedback.md)
- [Feedback on every variant](https://hextaui.com/docs/button/examples/variants-feedback.md)
- [Controlled status](https://hextaui.com/docs/button/examples/controlled-status.md)
- [As a link](https://hextaui.com/docs/button/examples/link.md)
- [Right to left](https://hextaui.com/docs/button/examples/rtl.md)
