UpdateButton

Updates the current record with a fixed data payload, without showing a form. Useful for buttons like "Reset views" or "Mark as published".

Installation

pnpm dlx shadcn@latest add @shadmin/update-button

Usage

Place the button inside a RecordContext, typically in the actions of an <Edit> or <Show> view, or in a DataTable row:

import { Edit, UpdateButton } from "@/components/admin";
 
const PostEditActions = () => (
  <>
    <UpdateButton label="Reset Views" data={{ views: 0 }} />
  </>
);
 
const PostEdit = () => <Edit actions={<PostEditActions />}>...</Edit>;

Defaults to mutationMode="undoable" — the update fires immediately and a notification with an undo button is shown for a few seconds. Pass mutationMode="pessimistic" (or use <UpdateWithConfirmButton>) to ask the user to confirm before firing the mutation.

Named exports

ExportBehavior
UpdateButtonDispatches to one of the variants below based on mutationMode (default: undoable)
UpdateWithUndoButtonFires immediately, shows undo notification
UpdateWithConfirmButtonOpens a confirmation dialog, fires on confirm

Props

PropRequiredTypeDefaultDescription
dataRequiredobject-Object passed to dataProvider.update()
classNameOptionalstring-Additional classes
confirmContentOptionalReactNodei18n computedBody of the confirmation dialog (Confirm variant)
confirmTitleOptionalReactNodei18n computedTitle of the confirmation dialog (Confirm variant)
iconOptionalReactNodeRefreshCw iconCustom icon
labelOptionalstringra.action.updatei18n key / label
mutationModeOptional"undoable" | "optimistic" | "pessimistic"undoableWhen to apply the mutation
mutationOptionsOptionalUseUpdateOptions-Forwarded to useUpdate
onClickOptional(e: MouseEvent<HTMLButtonElement>) => void-Additional click handler
redirectOptionalRedirectionSideEffect-Where to redirect after update
refOptionalRef<HTMLButtonElement>-Forwarded to the underlying <Button>
resourceOptionalstringFrom contextResource name
successMessageOptionalstring-Custom success i18n key
variantOptionalshadcn button variantoutlineButton style

icon

Replaces the default <RefreshCw /> shown alongside the label. Pass any lucide-react icon to convey a different action.

ref

Forwards a ref to the underlying <Button> element.

import { useRef } from "react";
import { UpdateButton } from "@/components/admin";
 
const ResetViewsButton = () => {
  const ref = useRef<HTMLButtonElement>(null);
  return <UpdateButton label="Reset Views" data={{ views: 0 }} ref={ref} />;
};
import { RotateCcw } from "lucide-react";
import { UpdateButton } from "@/components/admin";
 
<UpdateButton label="Reset Views" data={{ views: 0 }} icon={<RotateCcw />} />;

mutationMode

{
  /* Default: optimistic update with undo notification */
}
<UpdateButton label="Reset Views" data={{ views: 0 }} />;
 
{
  /* Equivalent */
}
<UpdateWithUndoButton label="Reset Views" data={{ views: 0 }} />;
 
{
  /* Pessimistic with confirmation dialog */
}
<UpdateButton
  label="Reset Views"
  data={{ views: 0 }}
  mutationMode="pessimistic"
/>;
 
{
  /* Equivalent */
}
<UpdateWithConfirmButton label="Reset Views" data={{ views: 0 }} />;

label

By default, the label is computed from the ra.action.update translation key, which reads "Update". You can customize the label for a specific resource by adding a resources.{resource}.action.update key to your translation messages:

const messages = {
  resources: {
    posts: {
      action: {
        update: "Update %{recordRepresentation}",
      },
    },
  },
};

Or pass a custom string directly:

<UpdateButton label="Reset Views" data={{ views: 0 }} />