Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
U-DI-Page opened this issue Sep 28, 2020 · 8 comments

Comments

@U-DI-Page
Copy link

image

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

@U-DI-Page
Copy link
Author

image

@gregg-cbs
Copy link

gregg-cbs commented Apr 14, 2021

@FourPig

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

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

@AbhisheshPradhan
Copy link

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,
    }}
>

@Ashkur
Copy link

Ashkur commented Jul 7, 2021

Same thing. Have you solve it?

@U-DI-Page
Copy link
Author

@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
Copy link
Author

Same thing. Have you solve it?

acturally not

@U-DI-Page
Copy link
Author

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

@AbhisheshPradhan
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants