Categories
React Answers

How to render multiple React components in the React.render() function?

Spread the love

Sometimes, we want to render multiple React components in the React render() function.

In this article, we’ll look at how to render multiple React components in the React render() function.

How to render multiple React components in the React.render() function?

To render multiple React components in the React render() function, we wrap them with a fragment.

For instance, we write

<React.Fragment>
  <h1>Page title</h1>
  <ContentComponent />
  {this.props.showFooter && <footer>(c) abc</footer>}
</React.Fragment>

to wrap our h1, ContentComponent and the footer with the React.Fragment fragment.

Then they’ll be rendered without any wrapping element.

Conclusion

To render multiple React components in the React render() function, we wrap them with a fragment.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *