Skip to Content
snapgrid is a react-grid-layout v2 alternative built on dnd-kit. Drag, resize, repack, and drag between grids.
DocumentationAPI ReferenceComponents

Components

GridLayout

The drop-in controlled grid. Children are keyed by their layout item’s i.

<GridLayout layout={layout} width={width} onLayoutChange={setLayout} gridConfig={{ cols: 12, rowHeight: 60, margin: [12, 12] }} resizeConfig={{ handles: ["se", "e", "s"] }} > {layout.map((item) => ( <div key={item.i}>{item.i}</div> ))} </GridLayout>

Props

PropTypeDefaultDescription
layoutLayoutRequired. Controlled array of items. Never mutated.
widthnumberRequired. Container width in px (from useContainerWidth).
onLayoutChange(layout: Layout) => voidCalled with the next layout when an interaction commits.
gridConfigPartial<GridConfig>see GridConfigColumns, row height, margins, padding, maxRows.
dragConfigDragConfigDrag behaviour.
resizeConfigResizeConfig{ handles: ["se"] }Resize behaviour.
dropConfigDropConfig{ enabled: false }Accept external draggables.
compactorCompactorverticalCompactorPacking algorithm.
isDraggablebooleantrueGrid-level drag toggle.
isResizablebooleantrueGrid-level resize toggle.
autoSizebooleantrueGrow the container height to fit content.
idstringauto (useId)Stable id for the droppable surface.
onDragStart onDrag onDragStopGridEventCallbackDrag lifecycle.
onResizeStart onResize onResizeStopGridEventCallbackResize lifecycle.
onDrop(layout, item, event) => voidFired when an external draggable is dropped in.
classNamestringAppended to snapgrid.
styleCSSPropertiesMerged over the surface’s positioning style.

ResponsiveGridLayout

Switches columns and layout by breakpoint as width changes. See Responsive layouts.

Props

PropTypeDefaultDescription
widthnumberRequired. Container width in px.
layoutsResponsiveLayoutsRequired. Per-breakpoint layout map.
onLayoutChange(layout, layouts) => voidActive layout and the updated map.
onBreakpointChange(breakpoint, cols) => voidFired when the active breakpoint changes.
breakpointsBreakpointsDEFAULT_BREAKPOINTSBreakpoint → min width (px).
colsBreakpointColsDEFAULT_BREAKPOINT_COLSBreakpoint → column count.
rowHeightnumber150Row height in px.
margin[number, number][10, 10]Gap between items.
containerPadding[number, number] | nullnullSurface padding; falls back to margin.
compactor dragConfig resizeConfig isDraggable isResizable autoSize className styleAs on GridLayout.

GridItem

A positioned tile with stable classes (snapgrid-item, data-grid-id, data-dragging) and the configured resize handles. Use it inside your own surface, or let GridLayout create them.

PropTypeDescription
idstringRequired. Matches the layout item’s i.
childrenReactNodeTile content.
classNamestringAppended to snapgrid-item.
styleCSSPropertiesMerged over the positioning style.

GridPlaceholder

Renders the landing-cell marker, or nothing when idle. Customize with className / style, or use useGridPlaceholder for full control.

GridDragOverlay

Renders the floating drag preview in a portal at document.body so it follows the pointer across grids unclipped. Takes a render function:

<GridDragOverlay>{(item) => <MyCard id={item.i} />}</GridDragOverlay>
PropTypeDescription
children(item: LayoutItem) => ReactNodeRequired. Renders the dragged item.
classNamestringAppended to snapgrid-overlay.
styleCSSPropertiesMerged over the positioning style.

SnapGridProvider

The headless provider. Same props as GridLayout minus className/style; instead of mapped children you render your own markup with the hooks. See Headless usage.

SnapGridGroup

Wraps multiple grids so tiles can be dragged between them: one shared dnd-kit provider and a registry. Takes only children. See Cross-grid dragging.

Item ids must be unique across all grids in a group.

Last updated on