react-resizable vs react-grid-layout vs react-splitter-layout
React Layout Management Libraries Comparison
1 Year
react-resizablereact-grid-layoutreact-splitter-layoutSimilar Packages:
What's React Layout Management Libraries?

React layout management libraries provide developers with tools to create responsive and dynamic layouts in React applications. These libraries facilitate the arrangement and resizing of components within a grid or split layout, enhancing user experience and interface flexibility. They are essential for applications that require complex layouts, allowing for a more organized and visually appealing presentation of content. Each library has its unique approach to handling layout management, catering to different use cases and developer preferences.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
react-resizable1,110,6432,467116 kB782 years agoMIT
react-grid-layout776,21820,852526 kB2294 months agoMIT
react-splitter-layout12,124431-386 years agoMIT
Feature Comparison: react-resizable vs react-grid-layout vs react-splitter-layout

Layout Flexibility

  • react-resizable:

    react-resizable provides flexibility in resizing components but does not impose a grid structure. This allows developers to implement resizable elements in any layout, offering more freedom in design choices. It is particularly useful for applications where specific dimensions are not constrained by a grid.

  • react-grid-layout:

    react-grid-layout offers a highly flexible grid system that allows components to be arranged in a grid format. It supports responsive layouts, enabling components to adapt to different screen sizes seamlessly. The grid can be customized with various breakpoints, making it suitable for complex layouts that require rearrangement based on user interactions.

  • react-splitter-layout:

    react-splitter-layout allows for the creation of resizable panels, giving users control over the layout. This feature is particularly beneficial in applications that require side-by-side comparisons or multi-pane views, enhancing user interaction with adjustable space allocation.

User Interaction

  • react-resizable:

    react-resizable focuses on providing a straightforward resizing experience. Users can click and drag to resize components, which is intuitive and enhances usability. This library is ideal for applications where users need to adjust the size of elements without altering their positions.

  • react-grid-layout:

    react-grid-layout excels in user interaction by enabling drag-and-drop functionality. Users can rearrange components easily, enhancing the dynamic nature of dashboards and similar applications. This interactivity is crucial for applications that prioritize user customization and engagement.

  • react-splitter-layout:

    react-splitter-layout enhances user interaction by allowing users to drag the splitter between panels to resize them. This feature is particularly useful in applications that require a multi-pane interface, providing a more interactive experience for users.

Ease of Integration

  • react-resizable:

    react-resizable is lightweight and can be easily integrated into any React component. Its simple API allows developers to add resizing capabilities without the need for extensive modifications to existing layouts, making it a flexible choice for enhancing UI components.

  • react-grid-layout:

    react-grid-layout is designed to integrate seamlessly with existing React applications. It provides a straightforward API and is compatible with various state management libraries, making it easy to incorporate into projects without significant refactoring.

  • react-splitter-layout:

    react-splitter-layout is also easy to integrate, providing a clear API for creating split layouts. It can be used alongside other layout libraries and is designed to work well within React's component-based architecture, ensuring minimal disruption to existing code.

Performance

  • react-resizable:

    react-resizable is lightweight and has minimal overhead, ensuring that the performance impact of adding resizing functionality is negligible. It is designed to be efficient, making it suitable for applications where performance is a key concern.

  • react-grid-layout:

    react-grid-layout is optimized for performance, utilizing virtualization techniques to manage large numbers of components efficiently. This ensures that even complex layouts remain responsive and performant, which is critical for applications with numerous draggable items.

  • react-splitter-layout:

    react-splitter-layout maintains good performance even with multiple resizable panels. It efficiently handles user interactions, ensuring that resizing actions do not lead to noticeable lag or performance degradation.

Customization

  • react-resizable:

    react-resizable allows for customization of the resizing handles and behavior, enabling developers to create a tailored resizing experience that fits the design of their application. This level of customization is beneficial for maintaining design consistency across components.

  • react-grid-layout:

    react-grid-layout offers extensive customization options, allowing developers to define grid layouts, breakpoints, and styles. This flexibility enables the creation of unique layouts tailored to specific application needs, enhancing the overall user experience.

  • react-splitter-layout:

    react-splitter-layout provides options for customizing the appearance and behavior of the splitters, allowing developers to create visually appealing and functional layouts that align with their application's design language.

How to Choose: react-resizable vs react-grid-layout vs react-splitter-layout
  • react-resizable:

    Choose react-resizable if your primary requirement is to allow users to resize components without the need for a grid structure. It provides a simple API for making any React component resizable, making it suitable for applications that require flexible component sizes.

  • react-grid-layout:

    Choose react-grid-layout if you need a powerful grid system that supports drag-and-drop functionality and responsive layouts. It is ideal for dashboard-like applications where components can be rearranged dynamically by users.

  • react-splitter-layout:

    Choose react-splitter-layout if you want to create a layout with adjustable panels that can be resized by dragging. This is particularly useful for applications that require a split view, such as code editors or file explorers.

README for react-resizable

React-Resizable

View the Demo

A simple widget that can be resized via one or more handles.

You can either use the <Resizable> element directly, or use the much simpler <ResizableBox> element.

See the example and associated code in ExampleLayout and ResizableBox for more details.

Make sure you use the associated styles in /css/styles.css, as without them, you will have problems with handle placement and visibility.

You can pass options directly to the underlying DraggableCore instance by using the prop draggableOpts. See the demo for more on this.

Installation

$ npm install --save react-resizable

Compatibility

React-Resizable 3.x is compatible with React >= 16.3. React-Resizable 2.x has been skipped. React-Resizable 1.x is compatible with React 14-17.

Usage

This package has two major exports:

  • <Resizable>: A raw component that does not have state. Use as a building block for larger components, by listening to its callbacks and setting its props.
  • <ResizableBox>: A simple <div {...props} /> element that manages basic state. Convenient for simple use-cases.

<Resizable>

const {Resizable} = require('react-resizable');

// ES6
import { Resizable } from 'react-resizable';

// ...
class Example extends React.Component {
  state = {
    width: 200,
    height: 200,
  };

  // On top layout
  onResize = (event, {node, size, handle}) => {
    this.setState({width: size.width, height: size.height});
  };

  render() {
    return (
      <Resizable height={this.state.height} width={this.state.width} onResize={this.onResize}>
        <div className="box" style={{width: this.state.width + 'px', height: this.state.height + 'px'}}>
          <span>Contents</span>
        </div>
      </Resizable>
    );
  }
}

<ResizableBox>

const {ResizableBox} = require('react-resizable');

// ES6
import { ResizableBox } from 'react-resizable';

class Example extends React.Component {
  render() {
    return (
      <ResizableBox width={200} height={200} draggableOpts={{...}}
          minConstraints={[100, 100]} maxConstraints={[300, 300]}>
        <span>Contents</span>
      </ResizableBox>
    );
  }
}

Props

These props apply to both <Resizable> and <ResizableBox>. Unknown props that are not in the list below will be passed to the child component.

type ResizeCallbackData = {
  node: HTMLElement,
  size: {width: number, height: number},
  handle: ResizeHandleAxis
};
type ResizeHandleAxis = 's' | 'w' | 'e' | 'n' | 'sw' | 'nw' | 'se' | 'ne';

type ResizableProps =
{
  children: React.Element<any>,
  width: number,
  height: number,
  // Either a ReactElement to be used as handle, or a function returning an element that is fed the handle's location as its first argument.
  handle: ReactElement<any> | (resizeHandle: ResizeHandleAxis, ref: ReactRef<HTMLElement>) => ReactElement<any>,
  // If you change this, be sure to update your css
  handleSize: [number, number] = [10, 10],
  lockAspectRatio: boolean = false,
  axis: 'both' | 'x' | 'y' | 'none' = 'both',
  minConstraints: [number, number] = [10, 10],
  maxConstraints: [number, number] = [Infinity, Infinity],
  onResizeStop?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any,
  onResizeStart?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any,
  onResize?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any,
  draggableOpts?: ?Object,
  resizeHandles?: ?Array<ResizeHandleAxis> = ['se']
};

The following props can also be used on <ResizableBox>:

{
  style?: Object // styles the returned <div />
}

If a width or height is passed to <ResizableBox>'s style prop, it will be ignored as it is required for internal function.

Resize Handle

If you override the resize handle, we expect that any ref passed to your new handle with represent the underlying DOM element.

This is required, as react-resizable must be able to access the underlying DOM node to attach handlers and measure position deltas.

There are a few ways to do this:

Native DOM Element

This requires no special treatment.

<Resizable handle={<div className="foo" />} />
Custom React Component

You must forward the ref and props to the underlying DOM element.

Class Components
class MyHandleComponent extends React.Component {
  render() {
    const {handleAxis, innerRef, ...props} = this.props;
    return <div ref={innerRef} className={`foo handle-${handleAxis}`} {...props} />
  }
}
const MyHandle = React.forwardRef((props, ref) => <MyHandleComponent innerRef={ref} {...props} />);

<Resizable handle={<MyHandle />} />
Functional Components
const MyHandle = React.forwardRef((props, ref) => {
  const {handleAxis, ...restProps} = props;
  return <div ref={ref} className={`foo handle-${handleAxis}`} {...restProps} />;
});

<Resizable handle={<MyHandle />} />
Custom Function

You can define a function as a handle, which will simply receive an axis (see above ResizeHandleAxis type) and ref. This may be more clear to read, depending on your coding style.

const MyHandle = (props) => {
  return <div ref={props.innerRef} className="foo" {...props} />;
};

<Resizable handle={(handleAxis, ref) => <MyHandle innerRef={ref} className={`foo handle-${handleAxis}`} {...props} />} />