I have a form which renders and inserts a component into a timeline, but I can't figure out how to get it to render a new submission chronologically, so that it gets inserted in the correct order.
This is what I've been trying so far.
render() {
return (
<div className="timeline-container">
<ul>
{this.state.activities
.sort((a, b) => a.date > b.date)
.map((activity, i) => (
<Activity
key={i}
data={activity}
handleDelete={this.handleDelete}
/>
))}
</ul>
</div>
);
}
And this is the Activity component:
<li>
<span></span>
<div className="activity-title">{this.state.activity.title}</div>
<div className="activity-info">{this.state.activity.description}</div>
<div className="activity-location">{this.state.activity.location}</div>
<div className="activity-date">{this.state.activity.date.slice(0, 10)}</div>
<button onClick={this.handleDelete.bind(this, this.state.activity.id)}>
Delete
</button>
</li>;
At the moment it is still automatically rendering when the form is submitted, but it isn't sorting them.