Design comparison
Solution retrospective
feedback would be appreciated
Community feedback
- @mseidel819Posted over 2 years ago
This looks good! I like the way you implemented the "time posted" feature. I was just using dates, so I want to look into how you did that.
When I upvote the 1st level comments, they aren't sorting. Try moving your sort function around to another place. From what I think I see, you initialize
comments
with a sorted array, but they never sort again after that first time. For example, what I did in my app was to sort the comments in the return function: {{ comments_map.sort((a, b) => { return b.score - a.score; }).map(comment => { return ( <Comment key={comment.id + comment.user.username} comment={comment} comments={comments} setComments={setComments} currentUser={currentUser} /> ) }) }
}
now, each time this component re-renders due to an updated state, it will sort the comments accordingly.
Marked as helpful1@ifeanyiihPosted over 2 years ago@mseidel819 thank you so much for this. Now I sort the comments just before updating the state.
setComments(comments_map.sort((a, b) => b.score - a.score));
For the "time posted" feature, I used
Date.now()
to get the timestamp and date-fns' date utility library from date-fns to format the date.thanks.
1
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord