1

Im using dnd-kit to drag and drop buttons, but when I drag them the button moves faster than the cursor and ends up in a different place than the cursor, as you can see here

This is the code Im using:

function GridWard(){
        return(
       <Grid container spacing={3} >
            <DndContext 
                onDragEnd={orderUpdate}>
                <SortableContext items={bedsSorted.map(bed => bed.order.toString())}>
                        <Droppable id="droppable">
                            {
                                bedsSorted.map((bed, index) => {
                                    return(
                                        
                                        <SortableItem
                                            key={index}
                                            id={index.toString()}>
                                            <BedButton name={bed.name} onClick={() => editBed(bed)}
                                                type="edit" active={bed.active} deleteCallBack={(e:Event) => deleteBed(e, bed)}
                                                gender={bed.gender === 0 ? "male" : bed.gender === 1 ? "female" : "any"} 
                                            />                                               
                                            </SortableItem>
                                        
                                    )
                                })
                            } 
                        </Droppable>
                    
                </SortableContext>
            </DndContext>
        </Grid>
     );
 }
subharb
  • 3,374
  • 8
  • 41
  • 72

1 Answers1

0

The problem may be here

  key={index}

Pass a proper key to the element, like a unique id, so reordering will work

Porkopek
  • 895
  • 9
  • 20