how to render child components in react.js recursively

前端 未结 3 1172
渐次进展
渐次进展 2020-12-07 22:46

I wanted to recursively add a react component from within its own component. I saw this example of a tree component which was mapping through the child TreeNodes and adding

3条回答
  •  遥遥无期
    2020-12-07 23:36

    If I create the child nodes as an object at the top of the render method, it works fine.

    export default class extends React.Component {
      let replies = null
      if(this.props.replies){
        replies = this.props.replies.map((reply) => {
          return (
            
          )
        })
      }
    
      render() {
        return (
          
    { replies }
    ) } }

提交回复
热议问题