React-Grid-Layout (RGL) is a powerful and flexible grid layout system for React applications, enabling draggable and resizable components with responsive breakpoint support. Unlike older solutions like Packery or Gridster, RGL is built purely with React, avoiding external dependencies such as jQuery. The current stable version is 2.2.3, with frequent patch releases addressing bugs and minor enhancements. Version 2.0.0 marked a significant rewrite, introducing a full TypeScript codebase and a modernized Hooks-based API for improved composability and performance. Key differentiators include its robust responsive behavior, native React implementation, and first-class TypeScript support since version 2, making it suitable for complex, enterprise-grade dashboards and user interfaces. Releases occur frequently for bug fixes and minor features, typically multiple times per month for patch versions.
npm install react-grid-layoutVerified import paths — ran on the pinned version, not inferred.
This example demonstrates a basic responsive, draggable, and resizable grid layout using the `Responsive` component with `WidthProvider` and local state management for layout changes. It includes custom breakpoints and grid items.
Migrate to the new Hooks API and composable configuration objects. Refer to the official migration guide or RFC for v2. If a quick migration is needed, consider using `react-grid-layout/legacy` which provides a v1-compatible wrapper.
Ensure the `width` prop is passed to `ReactGridLayout`, or wrap it with `WidthProvider` if using `Responsive`.
If immediate feedback on mouse down is required, use a standard `onMouseDown` event handler on your grid items instead of `onDragStart`.
Instead of mutating callback parameters, use the `onLayoutChange` callback to receive the new layout array and update your component's state accordingly. For custom constraints, use the new pluggable constraints system.
Do not use `react-grid-layout@2.2.0`. Upgrade to `2.2.1` or any later patch version (e.g., `2.2.3`) to avoid this bug.
Upgrade to `react-grid-layout@2.2.3` or newer, as this issue was addressed by deferring state updates to prevent the infinite loop.
When using `ReactGridLayout` directly, you must explicitly pass a `width` prop. If using `Responsive`, ensure it's wrapped with `WidthProvider`.
Ensure that the `layout` prop is an array where each item is an object with at least `i` (id), `x`, `y`, `w`, and `h` properties. Initialize it to an empty array (`[]`) if there are no items initially.
Upgrade to `react-grid-layout@2.2.3` or a later version. The library now defers state updates to prevent this error.
Use ESM `import` statements (e.g., `import { Responsive } from 'react-grid-layout';`). Ensure your project's `package.json` specifies `"type": "module"` if you intend to use ESM exclusively, or configure your bundler (Webpack, Rollup, Vite) correctly.