Skip to content
Discussion options

You must be logged in to vote

Managed to solve this:

function deleteSlide() {
    var temp = [...slides];
    temp.splice(currentIndex, 1);
    setSlides(temp);
}

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.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ajaypillay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant