Skip to content

Commit

Permalink
feat: completed recursive comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ap221882 committed Jan 28, 2023
1 parent a1b93bf commit 94049c9
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions Revision/machine_coding/nestedComments/CommentsComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,30 @@ import React from 'react';

import { comments } from './nestedCommentsData';

const renderComments = (comments) => {
return comments.map((comment, i) => {
return (
<div
style={{
marginLeft: '2rem',
padding: '0 1rem',
border: '1px solid black',
}}
>
<SingleCommentComponent
name={comment.name}
text={comment.text}
//~* Not a right way, fetch key from the data itself
// key={i}
/>
{comment?.replies && renderComments(comment?.replies)}
</div>
);
});
};

const CommentsComponent = () => {
return (
<div>
//~? We have make this mapping function a recursive function
{comments.map((comment, i) => {
return (
<SingleCommentComponent name={comment.name} text={comment.text} />
);
})}
</div>
);
return <div>{renderComments(comments)}</div>;
};

const SingleCommentComponent = ({ name, text }) => {
Expand Down

2 comments on commit 94049c9

@vercel
Copy link

@vercel vercel bot commented on 94049c9 Jan 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

namaste-react – ./Day12/github-api-project-ts

namaste-react-ap221882.vercel.app
namaste-react.vercel.app
namaste-react-git-main-ap221882.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 94049c9 Jan 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

namaste-react-parcel – ./Day3

namaste-react-parcel-ap221882.vercel.app
namaste-react-parcel-git-main-ap221882.vercel.app
namaste-react-parcel.vercel.app

Please sign in to comment.