Your experience on this site will be improved by allowing cookies
React Fragments
React Fragments is introduced from the 16.2 and above version, to facilitate the grouping off a list of children without adding extra nodes to the DOM.
Syntax:
|
Example:
class App extends React.Component { render() { return ( |
Importance of React Fragments:
Fragments Short Syntax:
For declaring fragments, there is another shorthand exists.
Example:
class Columns extends React.Component { render() { return ( <> WelcomeYou are in the world of ReactJS. ); } } |
Keyed Fragments:
In ReactJS, Key is the only attribute that can be passed with the Fragments, as it is needed for mapping a
collection to an array of fragments.
Example:
Function = (props) { return ( {props.items.data.map(item => ( |
0 comments