React Split Pane
react-split-pane is a modern, accessible, and TypeScript-first React component designed for creating resizable split layouts. The current stable version is v3.2.0, which is built entirely with React hooks and provides comprehensive type definitions. This library enables developers to create flexible layouts with multiple resizable panes, supporting both horizontal and vertical splits, as well as nested configurations. Key differentiators include full TypeScript support, robust accessibility features (keyboard navigation, ARIA), touch-friendly interactions for mobile devices, and easy theming via CSS variables. It boasts a small bundle size (< 5KB gzipped) and ensures performant resizing through requestAnimationFrame throttling. Releases are active, with several patches and minor versions pushed out for the v3 series, indicating ongoing development and maintenance.
Common errors
-
SplitPane does not render or appears collapsed.
cause The parent container of SplitPane lacks explicit width and height dimensions.fixEnsure the parent element of SplitPane has defined CSS properties for `width` and `height`, for example, `<div style={{ width: '100%', height: '100vh' }}><SplitPane>...</SplitPane></div>`. -
Pane sizes reset to default when the component unmounts or the page refreshes.
cause The application is not persisting the pane sizes between renders or sessions.fixImplement the `usePersistence` hook from `react-split-pane/persistence` to save and restore pane sizes to `localStorage` or `sessionStorage`. -
Error: Cannot assign to read only property 'exports' of object '#<Object>'
cause Attempting to import `react-split-pane` using CommonJS `require()` syntax in an environment expecting ES Modules.fixMigrate your import statements from `const { SplitPane } = require('react-split-pane');` to `import { SplitPane } from 'react-split-pane';`.
Warnings
- breaking Version 3.0.0 introduced a complete rewrite of the library, moving to a hooks-based architecture, full TypeScript, and new API patterns. Code written for v2.x or earlier will not be compatible.
- gotcha The `SplitPane` component uses `width: 100%` and `height: 100%` by default. Its parent container must have explicit dimensions defined (e.g., `height: 100vh` for vertical splits or a fixed pixel height) for the component to render correctly.
- behavior-change Prior to v3.0.5, controlled panes with fixed pixel sizes would incorrectly scale proportionally when the browser window or container resized. This behavior was fixed to maintain fixed pixel sizes as expected.
- api-change Version 3.1.0 replaced separate mouse and touch event handlers with the unified Pointer Events API for improved drag UX. The `onResize` and `onResizeStart` callbacks now include `event.pointerType`.
Install
-
npm install react-split-pane -
yarn add react-split-pane -
pnpm add react-split-pane
Imports
- SplitPane
const SplitPane = require('react-split-pane');import { SplitPane } from 'react-split-pane'; - Pane
import Pane from 'react-split-pane/Pane';
import { Pane } from 'react-split-pane'; - usePersistence
import { usePersistence } from 'react-split-pane';import { usePersistence } from 'react-split-pane/persistence';
Quickstart
import React from 'react';
import { SplitPane, Pane } from 'react-split-pane';
interface SidebarProps {}
const Sidebar: React.FC<SidebarProps> = () => (
<div style={{ padding: '20px', background: '#f0f0f0', height: '100%' }}>Sidebar Content</div>
);
interface MainContentProps {}
const MainContent: React.FC<MainContentProps> = () => (
<div style={{ padding: '20px', background: '#e0e0e0', height: '100%' }}>Main Application Content</div>
);
function App() {
return (
<div style={{ width: '100%', height: '100vh', display: 'flex' }}>
<SplitPane direction="horizontal">
<Pane minSize="200px" defaultSize="300px">
<Sidebar />
</Pane>
<Pane>
<MainContent />
</Pane>
</SplitPane>
</div>
);
}
export default App;