Skip to content

React

The React layer (@blocknote/block-view/react) provides hooks, components, and cell adapters for rendering database tables in React applications.

Initializes a CollectionManager with React lifecycle management. Returns a three-state result.

import { useCollectionManager } from "@blocknote/block-view/react";
type UseCollectionManagerParams = {
collectionId: string;
user: string | { type: string; id: string };
initialize: (params: {
collectionId: string;
user: { type: string; id: string };
}) => Promise<Omit<InitializeCollectionOptions, "collectionId" | "user">>;
};

Returns:

| { status: "loading" }
| { status: "error"; error: Error }
| { status: "success"; manager: CollectionManager }

Example:

const state = useCollectionManager({
collectionId: "tasks",
user: "alice", // shorthand for { type: "user", id: "alice" }
initialize: async () => ({
collectionSource: new InMemoryCollectionSource(data),
documentSource: new InMemoryDocumentSource(docs),
pageSize: 25,
}),
});
if (state.status === "loading") return <p>Loading...</p>;
if (state.status === "error") return <p>Error: {state.error.message}</p>;
// state.status === "success"
const manager = state.manager;

The initialize function is called once. The returned CollectionManager is automatically disposed when the component unmounts.

Connects a CollectionManager to a table view. Returns a CollectionTable for rendering.

import { useCollectionTableView } from "@blocknote/block-view/react";
interface UseCollectionTableViewOptions {
collectionManager: CollectionManager;
viewId: string;
propertyDefinitions: PropertyDefinition<any>[];
getEditable?: (document: Document, property: Property) => boolean;
editable?: () => boolean;
}
function useCollectionTableView(options: UseCollectionTableViewOptions): {
table: CollectionTable;
};

Example:

const { table } = useCollectionTableView({
collectionManager: manager,
viewId: manager.views[0].id,
propertyDefinitions: defaultPropertyDefinitions,
editable: () => true,
});
return <TableView table={table} editable />;

The getEditable callback controls per-cell editability:

const { table } = useCollectionTableView({
collectionManager: manager,
viewId,
propertyDefinitions: defaultPropertyDefinitions,
getEditable: (document, property) => {
// Only allow editing the "name" column
return property.id === "name";
},
});

Registers keyboard shortcuts for undo (Ctrl/Cmd+Z) and redo (Ctrl/Cmd+Shift+Z).

import { useUndoRedoHotkeys } from "@blocknote/block-view/react";
function MyTable({ table }) {
useUndoRedoHotkeys(table.undoRedoManager);
return <TableView table={table} editable />;
}

The top-level component for rendering a database table. Supports compound component composition for customization.

import { TableView } from "@blocknote/block-view/react";
<TableView table={table} editable={true}>
{/* Optional children to override default layout */}
</TableView>
PropTypeDefaultDescription
tableCollectionTablerequiredThe table instance from useCollectionTableView
editablebooleanfalseEnable editing, footer, and mutation toolbar actions
childrenReactNodeundefinedOverride the default layout with compound components

Without children, TableView renders: Toolbars + Table (with HeaderRow + Body) + Footer (when editable).

All compound components are exported from @blocknote/block-view/react. Use them as children of <TableView> to customize the layout.

Container for toolbar rows.

<TableView table={table} editable>
<Toolbars>
<ActionsToolbar>
<MainActionsToolbarGroup>
<MainActionsToolbarGroupItems />
{/* Custom buttons here */}
</MainActionsToolbarGroup>
</ActionsToolbar>
</Toolbars>
</TableView>

Container for header and body.

<Table>
<HeaderRow menuAfter={<MenuItem>Custom item</MenuItem>} />
<Body />
</Table>

Container for footer content.

<Footer>
<AddDocumentFooterButton />
<DeleteSelectedDocumentsFooterButton />
</Footer>
ComponentDescription
ToolbarsContainer for all toolbar rows
ActionsToolbarPrimary toolbar (filter, sort, settings buttons)
SortsFiltersToolbarActive filter/sort chip bar
MainActionsToolbarGroupGroup wrapper for toolbar buttons
MainActionsToolbarGroupItemsRenders the default toolbar buttons
ShowFiltersToolbarButtonToggle filter chip bar
ShowSortsToolbarButtonToggle sort chip bar
SortSettingsComboboxRootSort settings popover
PropertyVisibilitySettingsComboboxRootColumn visibility settings
TableSettingsMenuRootGeneral settings dropdown
MinimizeMainActionsToolbarButtonCollapse toolbar button
AddSortToolbarButtonAdd a new sort
ComponentDescription
TableTable container
HeaderRowColumn headers. Props: menuAfter (extra menu items)
BodyData rows
PropertyHeaderIndividual column header
HeaderMenuRootColumn header dropdown menu
HeaderResizeHandleColumn resize drag handle
AddPropertyHeader”+” button to add a new column
SelectAllRowsHeaderCheckbox header for row selection
ChangePropertyTypeSubmenuRootSubmenu for changing property type
ComponentDescription
FooterFooter container
AddDocumentFooterButton”+ New” button to add a row
DeleteSelectedDocumentsFooterButtonDelete selected rows button

Access table state from any component inside <TableView>:

import { useTableViewContext } from "@blocknote/block-view/react";
function MyComponent() {
const { table, editable, ref } = useTableViewContext();
// table: CollectionTable
// editable: boolean
// ref: RefObject<HTMLDivElement | null>
}
import { useTableContext } from "@blocknote/block-view/react";

Available inside <Table>. Returns table-specific rendering context.

import { useToolbarsContext } from "@blocknote/block-view/react";

Available inside <Toolbars>. Returns toolbar-specific state (active filters, sorts, visibility).

Each adapter exports a React component (cell renderer) and a complete PropertyDefinition. Import from @blocknote/block-view/react or @blocknote/block-view/react/adapters.

AdapterComponentDefinitionType
Plain TextPlainTextAdapterstringDefinition"string"
NumberNumberAdapternumberDefinition"number"
DateDateAdapterdateDefinition"date"
CheckboxCheckboxAdaptercheckboxDefinition"checkbox"
Single SelectSingleSelectAdaptersingleSelectDefinition"single-select"
Multi SelectMultiSelectAdaptermultiSelectDefinition"multi-select"
  • Adapters may represent data differently internally than in the data model
  • Reading from the model uses parse (string to typed value)
  • Writing to the model uses serialize (typed value to string, returning null to cancel)
  • All adapters handle null/undefined values gracefully
  • Import only what you use for optimal tree-shaking
import {
stringDefinition,
numberDefinition,
checkboxDefinition,
} from "@blocknote/block-view/react";
const myDefinitions = [stringDefinition, numberDefinition, checkboxDefinition];
const { table } = useCollectionTableView({
collectionManager: manager,
viewId,
propertyDefinitions: myDefinitions,
});

A convenience array containing all six built-in property definitions.

import { defaultPropertyDefinitions } from "@blocknote/block-view/react";
// Equivalent to:
// [stringDefinition, numberDefinition, dateDefinition, checkboxDefinition, singleSelectDefinition, multiSelectDefinition]

Two CSS files must be imported for the default table appearance:

import "@blocknote/block-view/react/styles.css"; // Table layout and structure
import "@blocknote/block-view/react/adapters/styles.css"; // Cell adapter styles
import { DevtoolsPanel, createDatabasePlugin } from "@blocknote/block-view/react/devtools";

A React component that renders a devtools panel showing operation history and collection snapshots.

Creates a TanStack Devtools plugin for the database:

import { createDatabasePlugin } from "@blocknote/block-view/react/devtools";
const databasePlugin = createDatabasePlugin();
// Use with TanStack Devtools

Enable devtools during initialization:

const state = useCollectionManager({
collectionId: "tasks",
user: "alice",
initialize: async () => ({
collectionSource,
documentSource,
devtools: true, // enables event emission
}),
});