# Custom cells with React

> Keep table behavior in Laravel and give one column an application-specific React renderer.

Source: https://inertiax.dev/articles/custom-cells-with-react/

A role column may need to show a short explanation alongside its value. That is a rendering concern: the application knows what each role means, and React owns how to present it.

That need does not require a second table definition in React. Laravel still owns the table’s query behavior; React owns the application-specific rendering. A custom type connects one backend column to a React cell.

## Name the rendering contract

Use a namespaced type for the role column:

Inside the users table definition

```php
use InertiaX\Table\Columns\TextColumn;

TextColumn::make('role', 'Role')
    ->type('acme/role');
```

`role` is the source field. `acme/role` is the rendering key. Keeping those names distinct lets another field use the same renderer without adopting the same database column name.

## Keep presentation in React

The cell uses the stored role value to choose application copy:

resources/js/components/role-cell.tsx

```tsx
import type { TableCellRendererProps } from '@inertiax/react-table';

const roleDescriptions: Record<string, string> = {
  admin: 'Workspace administration',
  member: 'Day-to-day access',
};

export function RoleCell({ cell }: TableCellRendererProps) {
  const role = typeof cell.value === 'string' ? cell.value : '';
  const description = roleDescriptions[role];

  return (
    <div className="role-cell">
      <strong>{role || 'Unassigned'}</strong>
      {description && <small>{description}</small>}
    </div>
  );
}
```

Keeping this copy beside the markup lets the interface explain a role without changing the value Laravel sends.

## Register it on the page

The page renders the table through `AppTable`, the wrapper from the [installation guide](https://docs.inertiax.dev/table/installation/) that connects tables to Inertia:

resources/js/components/app-table.tsx

```tsx
import { useQueryHost } from '@inertiax/react';
import { Table, type TableProps } from '@inertiax/react-table';

export type AppTableProps = Omit<TableProps, 'host'>;
export function AppTable(props: AppTableProps) {
  return <Table {...props} host={useQueryHost()} />;
}
```

Register the same key through `TableCustomizationOptions` and pass the object to that table:

resources/js/pages/users/index.tsx

```tsx
import type { TableCustomizationOptions } from '@inertiax/react-table';
import { AppTable } from '@/components/app-table';
import { RoleCell } from '@/components/role-cell';

const usersTable = {
  cellRenderers: [{ operation: 'register', key: 'acme/role', value: RoleCell }],
} satisfies TableCustomizationOptions;

export default function UsersIndex() {
  return <AppTable prop="users" table={usersTable} />;
}
```

The matching `acme/role` key connects the renderer to the Laravel column. The page adds presentation to the existing `users` table without redefining its fields or query controls. The [custom columns guide](https://docs.inertiax.dev/table/guide/custom-columns/) covers registration details.

## Keep query behavior in Laravel

A custom renderer changes presentation only. If you make this custom-type column searchable, supply a Laravel [`searchUsing()` callback](https://docs.inertiax.dev/table/guide/query-callbacks/#search-a-stored-field). Displaying “Workspace administration” beside `admin` does not make those words searchable.

The role cell’s copy and layout can now change in React while the rules for finding and accessing users stay with the Laravel query.
