Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React animation when removing an element

I am quite new to React. I am trying to learn by implementing a full CRUD. However, I am unable to get animation working well for removing a course from the list.

I have configured animation on transitionAppear and on transitionLeave. The transitionAppear works alright. I can't get the transitionLeave

This is my component: https://github.com/leonardoanalista/react-crud/blob/master/src/components/course/CourseListRow.js

This is the CSS for the animation: https://github.com/leonardoanalista/react-crud/blob/master/src/style.css#L66

Please let me know if there is a better approach.

Any help would be highly appreciated!

cheers Leonardo

like image 739
Leonardo Avatar asked Dec 22 '16 05:12

Leonardo


People also ask

What kind of transition do you need to use to animate the removal of an element?

Create another CSS animation called fadeOut , say. Then when you want to remove the element, change the animation property on the element to that new animation, and use the animationend event to trigger the actual removal of the element once the animation is done: $('. hide').

Is React good for animations?

React Spring is a modern animation library that is based on spring physics. It's highly flexible and covers most animations needed for a user interface. React Spring inherits some properties from React Motion, such as ease of use, interpolation, and performance.


1 Answers

You have ReactCSSTransitionGroup being rendered along with the group which is something you shouldn't be doing per here because the group needs to be mounted inside of the transition group. I understand that you want to do the transition on each row but for this to work it needs to be on a the tbody.

All what you need to do is take out ReactCSSTransitionGroup from CourseListRow component and add it to CourseList:

</thead>
<ReactCSSTransitionGroup
  transitionName="course-item"
  transitionLeave={true}
  transitionAppear={true}
  transitionAppearTimeout={2500}
  transitionEnterTimeout={1700}
  transitionLeaveTimeout={1000}
  component="tbody"
>
  {this.props.courses.map(course =>
    <CourseListRow key={course.id} course={course} removeCourse={this.props.removeCourse} />
  )}
</ReactCSSTransitionGroup>
</table>

I made a pull request on your repo with the bug fixed.

like image 114
Kafo Avatar answered Sep 28 '22 16:09

Kafo