Skip to content

Commit

Permalink
Convert Comments to functional component
Browse files Browse the repository at this point in the history
  • Loading branch information
arjxn-py committed Oct 15, 2023
1 parent 3a1df66 commit 6459739
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions src/components/comments/Comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import CommentsHeader from "./CommentsHeader";
import AddComment from "./AddComment";
import Comment from "./Comment";

// Define a type for your comment objects
interface CommentObject {
userName: string;
commentText: string;
Expand All @@ -14,22 +13,22 @@ interface CommentsProps {
comments: CommentObject[];
}

export class Comments extends React.Component<CommentsProps> {
render() {
const commentComponents = this.props.comments.map((comment, index) => (
<Comment
key={index}
userName={comment.userName}
commentText={comment.commentText}
/>
));
const Comments: React.FC<CommentsProps> = ({ amountComments, comments }) => {
const commentComponents = comments.map((comment, index) => (
<Comment
key={index}
userName={comment.userName}
commentText={comment.commentText}
/>
));

return (
<div>
<CommentsHeader amountComments={this.props.amountComments} />
<AddComment />
{commentComponents}
</div>
);
}
}
return (
<div>
<CommentsHeader amountComments={amountComments} />
<AddComment />
{commentComponents}
</div>
);
};

export default Comments;

0 comments on commit 6459739

Please sign in to comment.