This is a solution to the Interactive comments section challenge on Frontend Mentor.
Users should be able to:
- View the optimal layout for the app depending on their device's screen size
- See hover states for all interactive elements on the page
- Create, Read, Update, and Delete comments and replies
- Upvote and downvote comments
- Bonus: If you're building a purely front-end project, use
localStorage
to save the current state in the browser that persists when the browser is refreshed. - Bonus: Instead of using the
createdAt
strings from thedata.json
file, try using timestamps and dynamically track the time since the comment or reply was posted.
- React - JS library
- TypeScript
- TailwindCSS
From this project, i learned a lot about how does TypeScripts work and it's making me get used to it. But the most important lesson that i learnt is how does a reference type variable works such and built a recursive function to manipulate the origin object.
export function deleteComment(comments: Comment[], id: number) {
for (let i = 0; i < comments.length; i++) {
const comment = comments[i];
if (comment.id === id) {
comments.splice(i, 1);
return true;
}
if (comment.replies && comment.replies.length > 0) {
if (deleteComment(comment.replies, id)) {
return true;
}
}
}
return false;
}
In the future, i would like to improve this project by making a backend for this project using MongoDB, ExpressJS, and NodeJS so it can store the comment that has been published.
- Frontend Mentor - @kurniakun17
- Twitter - @kurniaakharisma