Skip to content

useActionStatus

One async action as a FancyButton status: pending while it runs, done briefly once it lands, then idle.

Call run with a promise, or with a function that returns one. status is pending while it runs, done for doneMs (1500 by default) once it resolves, then idle again. A rejection goes straight back to idle and is thrown again, so showing the error stays with the caller. A newer run supersedes an older one: the older result never changes the status. Hand status to @khaeli/fancy-button, which draws the loader and the done label from it.

Save button

Status: idle

A longer done state

When the action fails

Installation

npx shadcn@latest add @khaeli/use-action-status

Installs with

Nothing else. This item needs no other Registry item and no npm package.

Keyboard

EnterSpace
Start the action. While the button is pending or shows its done label, a press does nothing, so an action is never started twice.

Accessible name

  • The hook renders nothing. The button that takes its status keeps the label you give it, so change the label while the action runs (Saving) and @khaeli/fancy-button announces its done label once.
  • A failure is not a status. Catch what run throws and say what went wrong in an element with role="alert", next to the button.

Registry JSON

The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/use-action-status.json