Last active
February 22, 2024 10:04
-
-
Save ValeryVerkhoturov/e2d01b924019e4915f6df378725390a0 to your computer and use it in GitHub Desktop.
interview_task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from "react"; | |
| let comments = [ | |
| { | |
| id: 1, | |
| text: "message 1", | |
| }, | |
| { | |
| id: 2, | |
| text: "message 2", | |
| children: [ | |
| { | |
| id: 4, | |
| text: "message 4", | |
| children: [ | |
| { | |
| id: 7, | |
| text: "message 7", | |
| }, | |
| { | |
| id: 8, | |
| text: "message 8", | |
| children: [ | |
| { | |
| id: 9, | |
| text: "message 9", | |
| }, | |
| { | |
| id: 10, | |
| text: "message 10", | |
| }, | |
| ], | |
| }, | |
| ], | |
| }, | |
| { | |
| id: 5, | |
| text: "message 5", | |
| }, | |
| ], | |
| }, | |
| ]; | |
| const Comments = (props) => { | |
| return ( | |
| <div> | |
| {props.comments.map((comment) => ( | |
| <Comment key={comment.id} comment={comment} /> | |
| ))} | |
| </div> | |
| ); | |
| }; | |
| const Comment = (props) => { | |
| return ( | |
| <div style={{ marginLeft: '10px' }}> | |
| <p>{props.comment.text}</p> | |
| {props.comment.children && <Comments comments={props.comment.children} />} | |
| </div> | |
| ); | |
| }; | |
| const App = () => { | |
| return ( | |
| <div className="App"> | |
| <Comments comments={comments} /> | |
| </div> | |
| ); | |
| }; | |
| export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment