React Split

2.0.14 · active · verified Sun Apr 19

react-split is a React component that enables the creation of resizable split views in web applications. It functions as a lightweight, declarative wrapper around the core Split.js library. Developers define child components within a `<Split>` container, which are then rendered as resizable panes. The current stable version is 2.0.14, with an active release cadence focused on bug fixes and minor feature enhancements. Its primary strengths include ease of use, minimal overhead, and direct exposure of Split.js options via React props, allowing for straightforward integration of flexible, resizable layouts. The package also ships with full TypeScript type definitions.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to set up a basic horizontal split view using `react-split` with two child components. It includes various configuration options like initial `sizes`, `minSize`, `gutterSize`, and event handlers for drag start/end, along with basic styling for visual clarity.

import React from 'react';
import Split from 'react-split';

// Dummy components for demonstration purposes
const PaneA = () => (
  <div style={{ background: '#f0f0f0', padding: '20px', height: '100%', overflow: 'auto' }}>
    <h2>Pane A</h2>
    <p>This is the content for the first resizable pane. It starts at 25% of the container width.</p>
    <p>You can adjust its size by dragging the splitter.</p>
  </div>
);

const PaneB = () => (
  <div style={{ background: '#e0e0f0', padding: '20px', height: '100%', overflow: 'auto' }}>
    <h2>Pane B</h2>
    <p>This is the content for the second resizable pane. It starts at 75% of the container width.</p>
    <p>The `minSize` prop ensures panes don't shrink below a specified pixel value.</p>
  </div>
);

function App() {
  return (
    <div style={{ height: '500px', width: '80%', margin: '50px auto', display: 'flex', border: '1px solid #ddd', borderRadius: '4px', overflow: 'hidden' }}>
      <Split
        sizes={[25, 75]}
        minSize={100}
        expandToMin={false}
        gutterSize={10}
        gutterAlign="center"
        snapOffset={30}
        dragInterval={1}
        direction="horizontal"
        cursor="col-resize"
        className="split-container"
        elementStyle={(dimension, elementSize, gutterSize, index) => ({
          flexBasis: `calc(${elementSize}% - ${gutterSize}px)`
        })}
        gutterStyle={(dimension, gutterSize, index) => ({
          flexBasis: `${gutterSize}px`
        })}
        onDragStart={() => console.log('Drag started')}
        onDragEnd={(sizes) => console.log('Drag ended with sizes:', sizes)}
      >
        <PaneA />
        <PaneB />
      </Split>
    </div>
  );
}

export default App;

view raw JSON →