How to do it...

Let's see the new updates:

  1. Components can now return arrays and strings from render: Before, React forced you to return an element wrapped with a <div> or any other tag; now it is possible to return an array or string directly:
    // Example 1: Returning an array of elements.    render() {      // Now you don't need to wrap list items in an extra element      return [        <li key="1">First item</li>,        <li key="2">Second item</li>,        <li key="3">Third item</li>,      ];    }    // Example 2: Returning a string    render() {      return 'Hello World!';    }
  1. Also, React now has a new feature called Fragment, which also works as a special wrapper for elements. It can be specified with empty tags (<></>) or directly using React.Fragment:
    // Example 1: Using empty tags ...

Get React Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.