Skip to content

usePluginContext

usePluginContext<TPluginId>(): PluginContextValue<TPluginId extends never ? PluginArgsRegistry[TPluginId<TPluginId>] : unknown>

Defined in: Context.tsx:303

Hook to access table context from within a plugin component.

Note: data, selectedRows, and table are typed as unknown because plugins are defined generically and cannot know the specific row type at definition time. Cast as needed in your plugin implementation.

TPluginId extends string & object = string

The plugin ID for type-safe openArgs (optional)

PluginContextValue<TPluginId extends never ? PluginArgsRegistry[TPluginId<TPluginId>] : unknown>

function MyPluginComponent() {
const { table, data, selectedRows, useEvent } = usePluginContext();
useEvent("selection-change", (rows) => {
console.log("Selection changed:", rows);
});
return <div>Total rows: {data.length}</div>;
}
// First, register the plugin args type:
declare module "@izumisy/seizen-table/plugin" {
interface PluginArgsRegistry {
"row-detail": { row: Person };
}
}
// Then use with plugin ID for type-safe openArgs:
function RowDetailPanel() {
const { openArgs } = usePluginContext<"row-detail">();
// openArgs is typed as { row: Person } | undefined
const row = openArgs?.row;
}