Incorrect type definition provided for nodes argument in onSortEnd prop

Author: smtchahalCreated Jan 7, 2025Updated Jan 7, 2025

According to the type definition, nodes of onSortEnd is an array of HTMLElement:

https://github.com/clauderic/react-sortable-hoc/blob/caf3c4f5bfb30894639391ae75c1bfc2b707a127/types/index.d.ts#L26-L32

But in reality, to access the HTMLElement, you need to use nodes[0].node, which triggers TypeScript error:

javascript
<MySortableList
    // ...
    onSortEnd={({ oldIndex, newIndex, nodes }) => {
        console.log('nodes are', nodes); // {boundingClientRect: null, edgeOffset: null, node: HTMLElement, translate: null}[]
    
        const node = nodes[0].node
        console.log('the actual HTML element is', node);
    }}
    // ...
/>

So it looks like either the typedef is wrong, or the code is wrong.

Source: clauderic/react-sortable-hoc