I'm having a strange issue when implementing a drag-and-drop. The drag and drop has 2 levels, the Group and the Rank.
The intention is that every "overall group" (buttons at the top) maintain their own ranks for both Groups and Ranks. So if I move Type A - 1
to Rank 2 when I have Overall Group A
selected, I should be able to then select Overall Group B
and see Type A - 1
in rank 1.
The Group (outer) level works fine. When I change between "Overall" groups, the sorting remains tied to each respective overall group as seen below:
However when changing the Rank it changes for all overall groups. Even stranger, when console logging before my setState
(passed through props) I can see the props are already changed before calling! Somehow my props (and actually the state) object is being mutated before I call setState
.
A couple things I tried:
- smacking
key
everywhere and making them unique, in case this is a DnD problem - making copies of the props before ever passing it to a Draggable or a function that could potentially mutate it
I did make a codesandbox -- https://codesandbox.io/s/react-beautiful-dnd-nested-drag-bug-q89lot?file=/src/Wrapper.tsx:1649-2116
but functionally both Draggable's reuse a single onDragEnd
which does some logic to then call setOverallGroups()
which sets the groups and ranks for all groups at once