React Deleting Slide from array #4549
-
Hi, I can't seem to figure out how to delete a slide at the current index which is rendered from an array. Code Sandbox link here. I have tried:
But the problem is that it does a double delete when the state updates. If I only run Without explicitly calling
But I'm not quite sure why this isn't actually updating the Swiper instance, according to the docs that's what I believe it should be doing. I recognize that this isn't being called when the state updates in The ideal behavior is that the current view stays put, and when the current slide is deleted, the slide at How should I go about this? Appreciate any help, thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Managed to solve this:
Just had to use the spread EDIT: Updated Code Sandbox. To prevent re-rendering of all other array elements, the key of each element must be unique across renders. Fixed by setting the key to be a count, which is strictly increasing. |
Beta Was this translation helpful? Give feedback.
Managed to solve this:
Just had to use the spread
...
operator to copy the array correctly. Although it is worth noting that this resets the state for all the other rendered slides, I need to figure out how to fix that.EDIT: Updated Code Sandbox. To prevent re-rendering of all other array elements, the key of each element must be unique across renders. Fixed by setting the key to be a count, which is strictly increasing.