Return multiple React elements in a method without a wrapper element

前端 未结 10 938
南方客
南方客 2020-12-16 13:06

I\'m trying to return multiple React elements from a helper method. I could solve it simply by moving around some code, but I\'m wondering if there\'s a cleaner way to solve

10条回答
  •  無奈伤痛
    2020-12-16 13:41

    Try this:

    class Foo extends React.Component {
        _renderAuthor() {
            return {this.props.author}
        }
    
        render() {
            return (
              
    {this.props.title} {this.props.author && " by "} {this.props.author && this._renderAuthor()}
    ); } }

提交回复
热议问题