React quickstart
gridla/react is a headless adapter: it owns layout and gesture state, measures the canvas, wires pointer and keyboard input, and positions items. Appearance is yours.
Uncontrolled
Give GridProvider a defaultLayout and it keeps the state for you.
What each piece does:
GridProviderholds the source layout, projects it onto the measured canvas size (responsiveistrueby default), and runs the solvers during gestures.gap,snapDistance,snap, andonTraceare the sameSolveOptionsthe core takes.GridCanvasrenders adivwithposition: relative, measures itself withResizeObserver, and attaches the pointer and keyboard handlers. Give it a height.GridItemrenders adivpositioned withtransformand setsdata-gridla-active,data-gridla-selected, anddata-gridla-shiftedattributes for styling.resizeEdgesadds built-in resize handles.GridPreviewOutlinerenders a box where the active item will land when released, and nothing when there is no gesture.
Render the children from a stable list of ids (here the initial layout); GridItem subscribes to its own geometry, so the list itself does not need to rerender during a drag.
Controlled
Pass layout and onLayoutChange to keep the state yourself. The callback receives the next layout after every accepted change, expressed in the canvas size it was rendered at.
The second callback argument is a GridChangeDetail with the reason (move, resize, place, remove, update, transfer, set), the itemId, and the solver strategy. Use it to decide what to persist. See controlled state and persistence.
Styling
Items are unstyled divs. A minimal stylesheet:
The active item follows the pointer without a transition; siblings animate to where the solver put them. Keep durations short (120-220ms) and animate transform and size only. The styling guide covers every attribute, resize handle sizing through --gridla-handle-size, the preview outline, motion, states, and a starter stylesheet you can import with import 'gridla/base.css'.
Actions
useGridActions() returns imperative actions that go through the same solvers: move, resize, place, remove, update, select, setLayout, and cancel.
place, move, and resize return false when the solver rejected the request.
Try it
Next
- Custom rendering: render props, drag handles, and your own resize chrome.
- Keyboard controls: what the built-in handlers do and how to extend them.
- Multiple canvases:
GridTransferScopefor dragging between providers.