Since version React 16.2.0 we are able to return arrays and strings from the render method. Before, React forced us to return an element wrapped with <div> or any other tag; it was not 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 has implemented a new feature called Fragment, which also works as a special wrapper for elements. It can be specified with empty tags (<></>) or directly by using React.Fragment:
// Example 1: Using empty...