---
id: "packages/active-grid/api/use-grid-imperative"
title: "useGridImperative"
description: "useGridImperative: generated from the source of active-grid."
url: "/packages/active-grid/api/use-grid-imperative"
locale: "en"
revision: "g0mvjxwj5c-88bdbe1c:use-grid-imperative"
---

# useGridImperative

Exported by `@workspace/active-grid`. Generated from the package source; part of [the index of every export](/packages/active-grid/api).

## Functions, hooks and constants

**useGridImperative**: `<TData = unknown>(gridRef: RefObject<GridImperativeHandle \| null>) => UseGridImperativeResult<TData>`

Typed wrapper for an `ActiveGrid`'s imperative API. Returns stable
callbacks that safely no-op when the ref isn't attached yet.

Preferred over reading `gridRef.current?.X()` inline because:
- The returned callbacks are typed against `TData` for `addRow`.
- Each callback is stable across re-renders.
- Passing the result through context-menu / dialog builders avoids
the `react-hooks/refs` lint warning that fires when a ref-reading
function is invoked during render.

Usage:

```tsx
const gridRef = useRef<GridImperativeHandle>(null);
const grid = useGridImperative<Record>(gridRef);

const handleDelete = async (id: string) => {
const result = await deleteAction(id);
if (result.success) grid.removeRow(id);
};
```

**Client-mode caveat**: `addRow`/`removeRow` are no-ops in `mode="client"`
because client-mode reads directly from the `data` prop. Mutate your own
data state (`setData(prev => prev.filter(...))`) for client-mode grids.
The grid emits a dev-time warning if these are called in client mode.

Returns an object with:

| Prop | Type | Required | Description |
| --- | --- | --- | --- |
| `refetch` | `() => void` | yes | Invalidate server cache and re-fetch current page. No-op in client mode. |
| `removeRow` | `(rowId: string) => void` | yes | Remove a row from the local cache (server mode). In client mode, manage the `data` prop yourself — see README §Client-mode mutations. |
| `addRow` | `(row: TData) => void` | yes | Add a row to the local cache (server mode). In client mode, manage the `data` prop yourself. |
| `resetSelection` | `() => void` | yes | Clear all row selections. |
