So I have created a sortable list with each of it's items containing a toggle button, each toggle buttons is a component that has it own state either "on"/"off".
There's this weird behaviour that is happening after swapping, as shown below

It seems like SortableElement's children (toggle buttons) are getting their states mixed or something after swapping.
I've recreated the weird behaviour on this sandbox: https://codesandbox.io/s/react-sortable-hub-bug-gtxp3
You're not using a stable key prop for your sortable items. See https://reactjs.org/docs/lists-and-keys.html
Fixed sandbox:
https://codesandbox.io/s/react-sortable-hub-bug-izc06
The only code change I made was using value instead of index for the key of SortableItem
<SortableItem key={`item-${value}`}
Perfect, that did solved the issue for me :smiley::thumbsup:
Thank you very much for the fast reply :pray: I've also noticed that you've updated/fixed all code examples that had the issue and I really appreciate that :v:
Most helpful comment
You're not using a stable
keyprop for your sortable items. See https://reactjs.org/docs/lists-and-keys.htmlFixed sandbox:
https://codesandbox.io/s/react-sortable-hub-bug-izc06
The only code change I made was using
valueinstead ofindexfor the key ofSortableItem