02_lesson: Add orderedPost, so posts are listed in ascending order

02_lesson
Jason Zhu 2023-03-07 13:50:51 +11:00
parent 3b6ee94253
commit 1d970d5879
1 changed files with 5 additions and 1 deletions

View File

@ -6,7 +6,11 @@ import TimeAgo from "./TimeAgo";
const PostsList = () => {
const posts = useSelector(selectAllPosts);
const renderedPosts = posts.map((post) => (
const orderedPosts = posts
.slice()
.sort((a, b) => b.date.localeCompare(a.date));
const renderedPosts = orderedPosts.map((post) => (
<article key={post.id}>
<h3>{post.title}</h3>
<p>{post.content.substring(0, 100)}</p>