Skip to content

HistoryControls

Undo and redo a bounded edit history, including the branch created by a new change.

Live — this one is real

Usage

import { HistoryControls, useHistory, InlineEdit, Stack } from "mizu-ui";

export function Example() {
  const history = useHistory("First draft");
  return (
    <Stack gap={16}>
      <InlineEdit
        label="Draft name"
        value={history.value}
        onValueChange={history.set}
      />
      <HistoryControls
        canUndo={history.canUndo}
        canRedo={history.canRedo}
        onUndo={history.undo}
        onRedo={history.redo}
      />
    </Stack>
  );
}

Source & setup

Import mizu-ui/styles.css once. Fonts are optional via mizu-ui/fonts.css. Override --mizu-* tokens or use className for local styling. Uses native React and CSS; install the package peers for root imports.

Inspect interaction/HistoryControls.tsx

Source is included in the npm package under src/interaction/HistoryControls.tsx.

Open full source ↗

Props

PropTypeDefaultDescription
useHistory(initial, limit?)hook—Value, set, undo, redo, reset and availability; bounded to 50 past entries by default.
canUndo / canRedoboolean—Availability from your history.
onUndo / onRedofunction—Actual history operations.

Accessibility

Named button group with explicit disabled boundaries. Store immutable values; Object.is suppresses unchanged edits. A new edit clears the redo branch.

Motion

State changes belong to the edited content.

Works alongside