Scripts2026年7月25日·1 分钟阅读

react-grid-layout — Draggable Resizable Grid Layout for React

A draggable and resizable grid layout system for React with responsive breakpoints, inspired by Packery and Gridster.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
react-grid-layout Overview
直接安装命令
npx -y tokrepo@latest install 935ba8de-8868-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

react-grid-layout provides a grid layout system for React that supports dragging, resizing, and responsive breakpoints. Unlike jQuery-based alternatives, it is built entirely on React and works seamlessly with server-side rendering.

What react-grid-layout Does

  • Provides draggable and resizable grid items with collision detection
  • Supports responsive layouts with configurable breakpoints
  • Enables static (non-movable) grid items alongside draggable ones
  • Allows serialization and restoration of layout state
  • Handles both controlled and uncontrolled component patterns

Architecture Overview

The library wraps each child in a draggable and resizable container using react-draggable and react-resizable. Layouts are defined as arrays of position objects specifying x, y, width, and height in grid units. The ResponsiveGridLayout wrapper automatically selects the correct layout based on container width and defined breakpoints.

Self-Hosting & Configuration

  • Install via npm or yarn as a project dependency
  • Import the base CSS files for proper drag handle and resize styling
  • Configure grid properties: cols, rowHeight, width, and breakpoints
  • Use the onLayoutChange callback to persist layout state
  • Set compactType to control vertical or horizontal compaction behavior

Key Features

  • Pure React implementation with no jQuery dependency
  • Built-in responsive breakpoint support via ResponsiveGridLayout
  • Customizable drag handles and resize handles
  • Optional bounds checking to prevent items from leaving the grid
  • Server-side rendering compatible with no window dependency on initial render

Comparison with Similar Tools

  • Gridstack.js — jQuery-dependent grid; react-grid-layout is React-native
  • Packery — Masonry-style packing; react-grid-layout uses a strict grid model
  • react-mosaic — Window manager pattern; react-grid-layout focuses on dashboard grids
  • Muuri — Supports filtering and sorting; react-grid-layout prioritizes drag-resize simplicity
  • CSS Grid — Native but lacks built-in drag-and-drop and resize behavior

FAQ

Q: Can I use it with Next.js SSR? A: Yes. The library does not depend on window at import time. Use dynamic import with ssr:false if you encounter hydration issues.

Q: How do I make certain items non-draggable? A: Set static: true in the layout item object to lock its position and size.

Q: Does it support touch devices? A: Yes. react-draggable and react-resizable both handle touch events.

Q: How do I persist layouts across sessions? A: Use the onLayoutChange callback to serialize the layout array to localStorage or a backend.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产