V
V
vovashaplin2020-06-26 17:32:26
React
vovashaplin, 2020-06-26 17:32:26

How to make smooth removal of an array element with framer-motion?

I made an animation of removal from the array, but it does not work correctly. Shows the removal animation of the last element.
Here's a simple layout I made for ease of viewing.
https://codesandbox.io/s/awesome-edison-75p4t?file...
I would also like to implement a smooth replacement of the deleted element, and not just an unanimated shift.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2020-06-26
@vovashaplin

it turned out like this, I added a timeout to the Box so that it had time to animate before deleting
https://codesandbox.io/s/angry-payne-j0nhi

Shows the removal animation of exactly the last element

because here key=index shifted by one when removed, was not "unique for the block", but depended on the position in the array
{boxes.map((item, index) => (
  <Box key={index} item={item} onDelete={onDelete} />
 ))}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question