On the other hand, fragments let you group a list of children without adding extra nodes (HTML Elements) to the DOM, which results in a shallow DOM tree. To comply with this requirement, React developers usually wrap the HTML with an extra div element. It is a common pattern in React for a component to return multiple elements, but with the usual React component syntax and return, it always expects only a single HTML element to be returned. React fragments is a feature included in React to return more than one HTML element from a React Component. The problem when not using React fragments.In this tutorial, you will learn how to use React fragments to add multiple elements to a React component, let’s get started! Table of contents # The fragments feature was introduced in v 16.2 of React. React fragments solves the problem of returning multiple elements without the need of wrapping them in an extra Node (usually a div). React is one of the most popular JavaScript libraries.
0 Comments
Leave a Reply. |