Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
react-sortable
Advanced tools
Higher-order component for creating sortable lists with minimalistic implementation and without polyfills. Using just React.js and HTML5 DragEvent interface.
Mainly tested in latest stable Webkit, Firefox and IE.
To install a stable release use:
npm i react-sortable --save
First import the necessary dependencies.
import React from 'react';
import ReactDOM from 'react-dom';
import { sortable } from 'react-sortable';
Then create a component for the single item of the list.
class Item extends React.Component {
render() {
return (
<li {...this.props}>
{this.props.children}
</li>
)
}
}
var SortableItem = sortable(Item);
And create component for the whole list, which will be the main component.
class SortableList extends React.Component {
state = {
items: this.props.items
};
onSortItems = (items) => {
this.setState({
items: items
});
}
render() {
const { items } = this.state;
var listItems = items.map((item, i) => {
return (
<SortableItem
key={i}
onSortItems={this.onSortItems}
items={items}
sortId={i}>{item}</SortableItem>
);
});
return (
<ul className='sortable-list'>
{listItems}
</ul>
)
}
};
Now you can pass a list of items to the main component and render the whole result.
var items = [
"Gold",
"Crimson",
"Hotpink",
"Blueviolet",
"Cornflowerblue",
"Skyblue",
"Lightblue",
"Aquamarine",
"Burlywood"
]
ReactDOM.render(
<SortableList items={items} />,
document.body
);
You can see this simple working demo in the ./example
folder.
For visual styling, you can add className of your choice.
Component will automatically attach the necessary drag event handlers.
It expects the following properties to be defined:
Unfortunately, at the moment there is no support of this interface in mobile browsers.
This repository was published back in 2014 and was pretty much the very first implementation of drag and drop sortable list for React.js. Nowadays since there are other repositories which are well maintained (react-beautiful-dnd, react-sortable-hoc), I can recommend to use some of them in your project. This repository is now rather a showcase of what can be done just with simple React.js component and bare HTML5 API, having as few lines of code as possible. It can serve as inspiration for somebody who would like to reimplement this functionality from scratch.
FAQs
Make your React components sortable.
The npm package react-sortable receives a total of 522 weekly downloads. As such, react-sortable popularity was classified as not popular.
We found that react-sortable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.