Let's see the new updates:
- 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!'; }
- 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 ...