alepha@docs:~/docs/.content/release/docs/reference/react-hooks$
cat useConfirmedAction.md | pretty
1 min read
Last commit:

#useConfirmedAction

#Import

typescript
1import { useConfirmedAction } from "@alepha/ui/admin";

#Overview

The recurring admin pattern (confirm, then mutate, then toast) in one hook. Wraps useAction (so failures still emit react:action:error for the global toaster) plus useDialog().confirm and an optional success toast.

#Examples

tsx
 1const remove = useConfirmedAction<[FileResource, () => void]>( 2  { 3    confirm: (file) => ({ 4      title: tr("admin.files.deleteTitle", { default: "Delete file" }), 5      description: tr("admin.files.deleteConfirm", { 6        default: `Delete "${file.name}"?`, 7        args: [file.name], 8      }), 9      destructive: true,10    }),11    handler: async (file, refresh) => {12      await client.deleteFile({ params: { id: file.id } });13      refresh();14    },15    success: tr("admin.files.deleted", { default: "File deleted" }),16  },17  [client, tr],18);19// rowActions: onClick: (_f, { refresh }) => remove.run(file, refresh)