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

positional value of array element changing after deleting

Open Camelot93 opened this issue 5 years ago • 6 comments

Hey I have an issue, when i delete an element in an array with Rnd as a parent all elements that are ahead of the deleted one move to the position of the element before them. how do I change that?

Camelot93 avatar Dec 08 '19 23:12 Camelot93

Hi Camelot93, did you find a solution to this problem?

sanjitgroverincedo avatar Jul 07 '20 12:07 sanjitgroverincedo

Having the same thing :(

aktn avatar Jul 08 '20 09:07 aktn

@Camelot93 @aktn Could you please provide a reproduced example in codesandbox?

bokuweb avatar Jul 08 '20 09:07 bokuweb

Hi @Camelot93, my issue was I was displaying Rnd in row and col. When I added new Rnd on button click, it tends to get in another col causing the error. So I did, Container> {this.state.rnds.map(rnd->Rnd> <Rnd)} /Container> It resolved my issue. Hope this helps.

sanjitgroverincedo avatar Jul 08 '20 14:07 sanjitgroverincedo

@sanjitgroverincedo Thanks

bokuweb avatar Jul 11 '20 08:07 bokuweb

For anyone still having the same problem, I solved this by changing the index component's key to an identifier

Before: rnds.map((rnd, index) => <Rnd key={index} />) After: rnds.map(rnd => <Rnd key={rnd.id} />)

When deleting an element from the list, the index of its successor would change to the one that was deleted, causing the problem.

Aldemylla avatar Sep 03 '22 02:09 Aldemylla