It probably won't work because it requires setList and updates the list while moving mouse.
Here is an alternative:
https://virtuoso.dev/react-sortable-hoc/
import { useState, forwardRef } from 'react'
import { Virtuoso } from 'react-virtuoso'
import { sortableElement, sortableContainer } from "react-sortable-hoc"
const SortableContainer = sortableContainer(({ listRef, ...props }) => <ul {...props} ref={listRef} />)
const SortableItem = sortableElement((props) => <li {...props} />)
function App() {
const [state, setState] = useState([...Array(100)].map((_, i) => +i))
const components = {
List: forwardRef((props, ref) => {
return <SortableContainer {...props} listRef={ref} onSortEnd={({ newIndex, oldIndex }) => {
if (newIndex !== oldIndex) {
const temp = state[newIndex]
state[newIndex] = state[oldIndex]
state[oldIndex] = temp
setState([...state])
}
}} />
}),
Item: (props) => {
const { ['data-index']: index } = props
return <SortableItem index={index} {...props} />
},
}
return (
<Virtuoso
style={{ width: 110, height: 500 }}
data={state}
components={components}
itemContent={(index, row) => <>Item {row}</>}
/>
)
}
export default App