I am building an application with React and Reflux, and I am trying to display a list of elements in a specific order.
Elements are custom Post components that appear in reverse chronological order, so the last entry is at the top of the list.
I use the TimeoutTransitionGroup Khan Academy to make the list items disappear and disappear.
The problem that I see is that when I add a new message and the component receives the updated list through the new details, the transition occurs from the last element in the list, and not from the first. I would like to have it so that the first element fades, since this is the position of the new element that was added.
Message 2 <- This message was added recently.
Message 1 <- This message disappears in
Is there a way to specify the same order of elements, but do them in reverse order or something like that?
This is my component render function:
if (!(this.props.posts && this.props.ordering)) return false;
var posts = this.props.ordering.map(function(postId, index) {
return <Post key={index} post={this.props.posts[postId]}/>;
}, this);
return (
<div className="post-collection">
<TimeoutTransitionGroup
enterTimeout={500}
leaveTimeout={500}
transitionName="postTransition">
{posts}
</TimeoutTransitionGroup>
</div>
);
This is the CSS transition:
.postTransition-enter {
opacity: 0;
transition: opacity .25s ease-in;
}
.postTransition-enter.postTransition-enter-active {
opacity: 1;
}
.postTransition-leave {
opacity: 1;
transition: opacity .25s ease-in;
}
.postTransition-leave.postTransition-leave-active {
opacity: 0;
}
Any help would be greatly appreciated!