🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

react-grid-layout

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-grid-layout

A draggable and resizable grid layout with responsive breakpoints, for React.

1.5.1
latest
Version published
Weekly downloads
840K
4.22%
Maintainers
1
Weekly downloads
 
Created

What is react-grid-layout?

react-grid-layout is a powerful library for creating dynamic and responsive grid layouts in React applications. It allows developers to create draggable, resizable, and responsive grid layouts with ease.

What are react-grid-layout's main functionalities?

Draggable Grid Items

This feature allows you to create grid items that can be dragged around within the grid. The layout array defines the position and size of each grid item.

import React from 'react';
import GridLayout from 'react-grid-layout';

const layout = [
  {i: 'a', x: 0, y: 0, w: 1, h: 2},
  {i: 'b', x: 1, y: 0, w: 3, h: 2},
  {i: 'c', x: 4, y: 0, w: 1, h: 2}
];

const MyFirstGrid = () => (
  <GridLayout className="layout" layout={layout} cols={12} rowHeight={30} width={1200}>
    <div key="a">A</div>
    <div key="b">B</div>
    <div key="c">C</div>
  </GridLayout>
);

export default MyFirstGrid;

Resizable Grid Items

This feature allows you to create grid items that can be resized by dragging their edges. The isResizable property in the layout array enables resizing for each grid item.

import React from 'react';
import GridLayout from 'react-grid-layout';

const layout = [
  {i: 'a', x: 0, y: 0, w: 1, h: 2, isResizable: true},
  {i: 'b', x: 1, y: 0, w: 3, h: 2, isResizable: true},
  {i: 'c', x: 4, y: 0, w: 1, h: 2, isResizable: true}
];

const MyFirstGrid = () => (
  <GridLayout className="layout" layout={layout} cols={12} rowHeight={30} width={1200}>
    <div key="a">A</div>
    <div key="b">B</div>
    <div key="c">C</div>
  </GridLayout>
);

export default MyFirstGrid;

Responsive Grid Layout

This feature allows you to create grid layouts that adapt to different screen sizes. The layouts object defines the layout for different breakpoints, making the grid responsive.

import React from 'react';
import { Responsive, WidthProvider } from 'react-grid-layout';

const ResponsiveGridLayout = WidthProvider(Responsive);

const layouts = {
  lg: [
    {i: 'a', x: 0, y: 0, w: 1, h: 2},
    {i: 'b', x: 1, y: 0, w: 3, h: 2},
    {i: 'c', x: 4, y: 0, w: 1, h: 2}
  ],
  md: [
    {i: 'a', x: 0, y: 0, w: 1, h: 2},
    {i: 'b', x: 1, y: 0, w: 2, h: 2},
    {i: 'c', x: 3, y: 0, w: 1, h: 2}
  ]
};

const MyResponsiveGrid = () => (
  <ResponsiveGridLayout className="layout" layouts={layouts} breakpoints={{lg: 1200, md: 996}} cols={{lg: 12, md: 10}}>
    <div key="a">A</div>
    <div key="b">B</div>
    <div key="c">C</div>
  </ResponsiveGridLayout>
);

export default MyResponsiveGrid;

Other packages similar to react-grid-layout

FAQs

Package last updated on 11 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts