Skip to content
Grid LayoutAPI Reference

useDashboardGrid

comins-grid-layout@0.3.0React

Initial options, result fields, and event timing for connecting React state to DashboardGrid.

export declare function useDashboardGrid<TData = unknown>(options?: UseDashboardGridOptions<TData>): UseDashboardGridResult<TData>;
export type UseDashboardGridOptions<TData = unknown> = {
initialColumns?: number;
initialWidgets?: DashboardWidget<TData>[];
onLayoutMutation?: (event: DashboardLayoutMutationEvent<TData>) => void;
};
Option Default Meaning
initialColumns 12 Initial column count, normalized to 1–12.
initialWidgets [] Initial widgets; keep id and layout.id consistent.
onLayoutMutation None Receives transitions in an effect after reducer updates, including a snapshot suitable for consumer persistence.

Initial inputs are read once on mount. Changing initialWidgets later does not synchronize state. Use restoreLayout for a complete external snapshot or individual commands for partial edits. Do not mutate the initial input objects in place.

Events contain kind, widgetIds, columns, and snapshot. The snapshot describes the full state after the transition. Events are delivered for observed commands returning a new state object, excluding refreshLayout and reads. The callback does not persist anything automatically.

export type UseDashboardGridResult<TData = unknown> = {
state: DashboardLayoutState<TData>;
widgets: DashboardWidget<TData>[];
columns: DashboardLayoutState<TData>["columns"];
refreshVersion: number;
commands: DashboardGridCommands<TData>;
};
Field Usage
state Complete current state; do not mutate directly.
widgets state.widgets; pass to DashboardGrid.widgets.
columns state.columns; pass to DashboardGrid.columns.
refreshVersion Pass to DashboardGrid.refreshKey.
commands 20 state commands; use the current render’s object.

Pass state into the view and connect onLayoutCommit back to commands so drag results reach React state. The hook does not render widget content. Call it at the top level of a React function component or custom hook.

The npm declarations below were compared with a fixed source snapshot. The snapshot is the commit recorded in the public artifact provenance.