Open GradySain opened 1 year ago
Okay I think I have a fix.
Found a similar issue addressed here: https://github.com/clauderic/dnd-kit/issues/183
I was using an array of objects as the items in SortableContext, as opposed to an array of ints.
For anyone that wants to fix the stack blitz link above and learn how the fix works:
const itemIds = useMemo(() => props.droppedItems.map((item) => item.sortID), [props.droppedItems]);
<SortableContext items={itemIds} strategy={rectSortingStrategy}>
I've got the same issue. I am doing everything in that was suggested above, but no dice. The <SortableContext>
is getting an array of strings, but still no animations. Any other pointers?
Ah! Nevermind! The <SortableContext>
needs INTs! Not strings! At least that is what fixed it for me.
Doesn't need ints but does need an array of unique ids. So instead of passing an array of todos, for example, you need to pass an array of todo ids.
const [items, setItems] = useState(todos.map((todo) => todo.id))
<SortableContext items={items} strategy={verticalListSortingStrategy} >
{items.map((item) => (
<SortableItem key={item} id={item} />
))}
</SortableContext>
Hello,
Here is a link to my issue - set up in StackBlitz.
https://stackblitz.com/edit/react-dnitfq?file=src/components/App.js
I am trying to build a fairly complex (for me) scenario:
The problem- the sortable elements do not animate when they are being dragged. But once they are dropped, their order is correct.
I think I am doing something wrong (either a small error, or a very big misunderstanding of how to set this up). Any help would be greatly appreciated :)