From 1d970d5879c13981f33d3f37296df4ba5ee74c2a Mon Sep 17 00:00:00 2001 From: Jason Zhu Date: Tue, 7 Mar 2023 13:50:51 +1100 Subject: [PATCH] 02_lesson: Add orderedPost, so posts are listed in ascending order --- 02_lesson_starter/src/features/posts/PostsList.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/02_lesson_starter/src/features/posts/PostsList.js b/02_lesson_starter/src/features/posts/PostsList.js index c897da5..3a1a5aa 100644 --- a/02_lesson_starter/src/features/posts/PostsList.js +++ b/02_lesson_starter/src/features/posts/PostsList.js @@ -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) => (

{post.title}

{post.content.substring(0, 100)}