Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-sortablejs

Package Overview
Dependencies
Maintainers
4
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-sortablejs

React bindings to [SortableJS](https://github.com/SortableJS/Sortable)

  • 6.0.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created

What is react-sortablejs?

react-sortablejs is a React wrapper for the SortableJS library, which provides drag-and-drop functionality for lists and grids. It allows for easy reordering of items within a list or grid, with support for various customization options and event handling.

What are react-sortablejs's main functionalities?

Basic Drag-and-Drop

This feature allows you to create a simple drag-and-drop list. The items in the list can be reordered by dragging and dropping.

import React from 'react';
import Sortable from 'react-sortablejs';

const SimpleList = () => {
  const items = ['Item 1', 'Item 2', 'Item 3'];
  return (
    <Sortable tag="ul">
      {items.map((item, index) => (
        <li key={index}>{item}</li>
      ))}
    </Sortable>
  );
};

export default SimpleList;

Handling Events

This feature demonstrates how to handle events such as the end of a drag-and-drop action. The `onEnd` event handler logs the event details when an item is moved.

import React from 'react';
import Sortable from 'react-sortablejs';

const EventHandlingList = () => {
  const items = ['Item 1', 'Item 2', 'Item 3'];

  const handleEnd = (evt) => {
    console.log('Item moved:', evt);
  };

  return (
    <Sortable tag="ul" onEnd={handleEnd}>
      {items.map((item, index) => (
        <li key={index}>{item}</li>
      ))}
    </Sortable>
  );
};

export default EventHandlingList;

Custom Drag Handle

This feature allows you to specify a custom handle for dragging items. In this example, only the elements with the class `handle` can be used to drag the list items.

import React from 'react';
import Sortable from 'react-sortablejs';

const CustomHandleList = () => {
  const items = ['Item 1', 'Item 2', 'Item 3'];
  return (
    <Sortable tag="ul" handle=".handle">
      {items.map((item, index) => (
        <li key={index}>
          <span className="handle">::</span> {item}
        </li>
      ))}
    </Sortable>
  );
};

export default CustomHandleList;

Other packages similar to react-sortablejs

FAQs

Package last updated on 14 Jan 2022

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc