I have been looking around for an example of adding items to a list with react and having it animate the newly added item, but not to the end of the list, but the beginning of the list. I found this example, but all the messing around I have done locally and online, I cant seem to get the item to animate when added to the first spot in the array. Here is a simple react todo add item. How can I get the item to add to the first spot, and do the animation to the first spot?
JS Fiddle: http://jsfiddle.net/kb3gN/13152/
var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup;
var TodoList = React.createClass({
getInitialState: function() {
return {items: ['hello', 'world', 'click', 'me']};
},
handleAdd: function() {
var newItems =
this.state.items.concat([prompt('Enter some text')]);
this.setState({items: newItems});
},
handleRemove: function(i) {
var newItems = this.state.items;
newItems.splice(i, 1)
this.setState({items: newItems});
},
render: function() {
var items = this.state.items.map(function(item, i) {
return (
<TodoItem item={item} key={item} onClick={this.handleRemove.bind(this, i)}/>
);
}.bind(this));
return (
<div>
<div><button onClick={this.handleAdd}>Add new</button></div>
<ReactCSSTransitionGroup transitionName="example">
{items}
</ReactCSSTransitionGroup>
</div>
);
}
});
React.render(<TodoList/>, document.getElementById('list'));