Nested comments in Reactjs

后端 未结 2 1971
一整个雨季
一整个雨季 2021-02-10 20:18

I have the following json:

{  
  \"comments\":[  
    {  
      \"id\":1,
      \"comment_text\":\"asdasdadasdsadsadadsa\",
      \"author\":\"adsfasdasdsad\",
          


        
2条回答
  •  心在旅途
    2021-02-10 21:15

    You need two components: Comments and Comment.

    Comment = React.createClass({
      render: function(){
        var comment = this.props.comment;
        return 

    {comment.author} says {comment.comment_text}

    } }); Comments = React.createClass({ render: function(){ return
    {this.props.comments.map(function(comment){ return })
    } });

    The Comment renders Comments, which in turn can render Comment nodes, etc. This recursively builds the comment structure.

提交回复
热议问题