react-sortablejs
react-sortablejs copied to clipboard
react clone the same item form another list , and the item's key is repeat?

the item.id will repeat in container list, what should i do?

@FourPig
prefix your key with a property that is specific to that list?
<div key={`list1-${item.id}`}
In my case, I'm cloning items from options (list 1) to canvas (list 2). I only want to update the canvas and not the options. For cloning and creating new ids for the options, I did the following for the options list
- set the list prop as a state
- setList to empty function so I can update the list items manually
- trigger updating the list items using onEnd hook to update the ids
<ReactSortable
list={optionsList}
setList={() => {}}
// After dropping, update the ids of options in list 1
// This is done to make id unique for dropped elements by updating the ids in list 1
onEnd={this._onDrop}
{...sortableOptions}
group={{
name: 'options',
pull: 'clone' as 'clone',
put: false,
}}
>
Same thing. Have you solve it?
@FourPig
prefix your key with a property that is specific to that list?
<div key={`list1-${item.id}`}
clone tow items to one list, the ids still will duplicate
Same thing. Have you solve it?
acturally not
In my case, I'm cloning items from options (list 1) to canvas (list 2). I only want to update the canvas and not the options. For cloning and creating new ids for the options, I did the following for the options list
- set the list prop as a state
- setList to empty function so I can update the list items manually
- trigger updating the list items using onEnd hook to update the ids
<ReactSortable list={optionsList} setList={() => {}} // After dropping, update the ids of options in list 1 // This is done to make id unique for dropped elements by updating the ids in list 1 onEnd={this._onDrop} {...sortableOptions} group={{ name: 'options', pull: 'clone' as 'clone', put: false, }} >
it's complicated
In my case, I'm cloning items from options (list 1) to canvas (list 2). I only want to update the canvas and not the options. For cloning and creating new ids for the options, I did the following for the options list
- set the list prop as a state
- setList to empty function so I can update the list items manually
- trigger updating the list items using onEnd hook to update the ids
<ReactSortable list={optionsList} setList={() => {}} // After dropping, update the ids of options in list 1 // This is done to make id unique for dropped elements by updating the ids in list 1 onEnd={this._onDrop} {...sortableOptions} group={{ name: 'options', pull: 'clone' as 'clone', put: false, }} >it's complicated
Update the id of the original list items after cloning.