
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
use-sortablejs
Advanced tools
SortableJS ported to React hooks.
Demo: https://harrel56.github.io/use-sortablejs
Created to serve as a refreshed alternative to react-sortablejs, with hook design inspired by @mui/base.
Currently, package is only available as ES module.
npm i use-sortablejs
Contains no external dependencies, only peer dependencies:
react: ^17.0.0 || ^18.0.0sortablejs: ^1.0.0@types/react: ^17.0.0 || ^18.0.0@types/sortablejs: ^1.0.0Package exports:
SortableProvider: sortable context provider,useSortable: main hook which requires access to sortable contextSupports:
SortableJS,Before using useSortable hook, it's required to wrap your application with SortableProvider.
Preferably, there should be only one SortableProvider per whole application, but it's not mandatory.
Nevertheless, interactions between two sortables in separate contexts have undefined behaviour.
Example:
// App.tsx
import {SortableProvider} from 'use-sortablejs'
import List from './List'
const App = () => {
return (
<SortableProvider>
<List/>
</SortableProvider>
)
}
// List.tsx
import {useState} from 'react'
import {useSortable} from 'use-sortablejs'
const List = () => {
const [items, setItems] = useState([
'Item 1',
'Item 2',
'Item 3',
'Item 4',
'Item 5'
])
const {getRootProps, getItemProps} = useSortable({setItems, options: {animation: 150}})
return (
<div {...getRootProps()}>
{items.map(item => <div key={item} {...getItemProps(item)}>{item}</div>)}
</div>
)
}
Where item type can be possibly anything (primitive, object of any shape, function).
All types definitions can be found in this file.
useSortable takes UseSortableProps parameter, which is an object containing:
setItems: Dispatch<SetStateAction<T[]>>, where T is your item type. In most cases this should be a setState function returned from React useState hook.options: ExtendedOptions<T>, options object which you would normally pass to Sortable.create().cloneItem: (item: T) => T, clone function to perform when item is being cloned. Defaults to internal shallow clone function.sortableRef: LegacyRef<Sortable>, ref object or ref callback, which will be set/called with created Sortable object - set to null on dismount.Additionally, all event functions that you pass to options object will have access to extended event object (SortableEventExtended<T>),
which contains additional field stateItem, which corresponds to dragged item state and is directly mapped from item field.
sortableRefLeveraging options reactivity is the preferred way of achieving dynamic changes to Sortable object, but if you need more control sortableRef is the way to go.
const myRef = useRef<Sortable>(null)
const {getRootProps, getItemProps} = useSortable({setItems, sortableRef: myRef})
const myCallbackRef = (sortable: Sortable | null) => {
sortable?.option('sort', false)
}
const {getRootProps, getItemProps} = useSortable({setItems, sortableRef: myCallbackRef})
getRootProps() should have set props from getItemProps(item).getRootProps() should contain unique key prop (NOT list index).setItems function should cause rerender of sortable list to reflect items state.Behaviour is undefined if any of these constraints is not met.
FAQs
SortableJS ported to React hooks
The npm package use-sortablejs receives a total of 156 weekly downloads. As such, use-sortablejs popularity was classified as not popular.
We found that use-sortablejs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.