react-sortablejs icon indicating copy to clipboard operation
react-sortablejs copied to clipboard

react clone the same item form another list , and the item's key is repeat?

Open U-DI-Page opened this issue 5 years ago • 8 comments

image

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

U-DI-Page avatar Sep 28 '20 07:09 U-DI-Page

image

U-DI-Page avatar Sep 28 '20 08:09 U-DI-Page

@FourPig

prefix your key with a property that is specific to that list?

<div key={`list1-${item.id}`}

gregg-cbs avatar Apr 14 '21 14:04 gregg-cbs

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

  1. set the list prop as a state
  2. setList to empty function so I can update the list items manually
  3. 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,
    }}
>

AbhisheshPradhan avatar Jul 07 '21 03:07 AbhisheshPradhan

Same thing. Have you solve it?

Ashkur avatar Jul 07 '21 19:07 Ashkur

@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

U-DI-Page avatar Jul 12 '21 02:07 U-DI-Page

Same thing. Have you solve it?

acturally not

U-DI-Page avatar Jul 12 '21 02:07 U-DI-Page

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

  1. set the list prop as a state
  2. setList to empty function so I can update the list items manually
  3. 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

U-DI-Page avatar Jul 12 '21 02:07 U-DI-Page

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

  1. set the list prop as a state
  2. setList to empty function so I can update the list items manually
  3. 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.

AbhisheshPradhan avatar Jul 12 '21 03:07 AbhisheshPradhan