React SortableJS Bindings

6.1.4 · active · verified Sun Apr 19

react-sortablejs provides idiomatic React bindings for the powerful SortableJS drag-and-drop library, enabling developers to create interactive, sortable lists with declarative React components. It abstracts away direct DOM manipulation, integrating smoothly with React's state management. The package is currently at version 6.1.4 and receives maintenance updates focusing on bug fixes and dependency updates, though the README indicates it's "not considered ready for production". It differentiates itself by offering a ReactSortable component that directly accepts SortableJS options as props, along with supporting both functional and class-based React components and providing clear mechanisms for integrating SortableJS plugins like MultiDrag and Swap.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic sortable list using a React functional component with local state management for drag-and-drop reordering.

import React, { FC, useState } from "react";
import { ReactSortable } from "react-sortablejs";

interface ItemType {
  id: number;
  name: string;
}

export const BasicFunction: FC = () => {
  const [state, setState] = useState<ItemType[]>([
    { id: 1, name: "shrek" },
    { id: 2, name: "fiona" },
    { id: 3, name: "donkey" },
  ]);

  return (
    <div style={{ maxWidth: '300px', margin: '20px auto', border: '1px solid #eee', padding: '10px' }}>
      <h3>Drag and Drop List</h3>
      <ReactSortable list={state} setList={setState} animation={150} group="shared-group">
        {state.map((item) => (
          <div 
            key={item.id}
            style={{
              padding: '10px',
              margin: '5px 0',
              border: '1px solid #ccc',
              backgroundColor: '#f9f9f9',
              cursor: 'grab'
            }}
          >
            {item.name}
          </div>
        ))}
      </ReactSortable>
    </div>
  );
};

view raw JSON →