Skip to content

14. Fragment

Course: React - chapter 14

In React, a component can return a single parent element, but it can contain multiple children within that single parent

const MyComponent = () => {
return (
<h1>Hello</h1>
<p>World</p> // This line will cause an error
);
};
const MyComponent = () => {
return (
<>
<h1>Hello</h1>
<p>World</p>
</>
);
};