Rendering nested/threaded comments in React

前端 未结 2 1516
隐瞒了意图╮
隐瞒了意图╮ 2021-02-06 11:35

Given the below array, I\'d like to render comments in a threaded manner by making use of parentId.

comments: [
    {
      id: 1,
            


        
2条回答
  •  旧时难觅i
    2021-02-06 11:45

    in case you need an example that needs to go unknown levels deep i solved with this

    function Comment({text, author}){
      return 
    {author}: {text}
    } CommentTree(comments) { let items = comments.map((comment) => { return (
    {comment.children && CommentTree(comment.children)}
    ) }) return items }

提交回复
热议问题