let handleSort = (column:Column.columnSelection) => {
let list = Js.Array.copy([selectedcolum])
let columnIndex = selectedcolum->Js.Array2.findIndex((c)=> c.id == column.id)
Js.log(columnIndex)
let draggedItemContent = selectedcolum->Js.Array2.map((x)=> x.id == column.id ? x : column)
let draggedItemContent = draggedItemContent->Js.Array.spliceInPlace(~pos= (draggedItemContent->Js.Array2.length)-1, ~remove=draggedItemContent->Js.Array2.length, ~add=[])
//switch the position
list->Js.Array2.spliceInPlace(~pos= (draggedItemContent->Js.Array2.length)-1, ~remove=0, ~add=draggedItemContent)
//reset the position ref
dragItem.current = Js.Nullable.null
dragOverItem.current = Js.Nullable.null
setItems(list)
}
I don’t understand your problems? What isn’t compatible? The spliceInPlace function exists and without testing your code, it looks like you’re using it right.
Okay, I thought you have problems with react but didn’t mention it anywhere. Maybe you mean “As splice doesn’t work in react”?!
Well, I have to guess again: Your component doesn’t update?
If that is your case, then it’s the same problem as in native JavaScript. The spliceInPlace mutates the array but you have to reference a new array to update your component.
So there are two solutions:
Create a copy of your items, splice it and then use setItems(copy)
Get all Items until the index (inclusive?), get all items after the index, concat it with your new item.
Here an example in TypeScript, but you can easily adopt it to rescript: