# useGridUndoRedo

Hook for programmatic undo/redo control.

Must be used within a DataGrid component tree with undoRedo and editing enabled.

```ts
useGridUndoRedo(selector: string): UndoRedoMethods
```

## Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| `selector` | <code>string</code> | Optional CSS selector to target a specific grid element via
  DOM query instead of using React context. Use when the component contains
  multiple grids, e.g. `'tbw-grid.primary'` or `'#my-grid'`. |

#### Example

```tsx
import { useGridUndoRedo } from '@toolbox-web/grid-react/features/undo-redo';

function UndoRedoControls() {
  const { undo, redo, canUndo, canRedo, clearHistory } = useGridUndoRedo();

  return (
    <div>
      <button onClick={undo} disabled={!canUndo()}>Undo</button>
      <button onClick={redo} disabled={!canRedo()}>Redo</button>
      <button onClick={clearHistory}>Clear History</button>
    </div>
  );
}
```
