46
loading...
This website collects cookies to deliver better user experience
const App = () => {
return (
<div>
<ChildA />
<ChildB />
<ChildC />
</div>
);
}
const App = () => {
return (
<React.Fragment>
<ChildA />
<ChildB />
<ChildC />
</React.Fragment>
);
}
const App = () => {
return (
<>
<ChildA />
<ChildB />
<ChildC />
</>
);
}
const Login = ({isLoggedIn, name}) => {
{isLoggedIn ? (
<>
<h3>Welcome {name}</h3>
<p>
You are logged in!
</p>
</>
) : (
<>
<h3>Login</h3>
<input type="text" id="username" />
<input type="password" id="password" />
<input type="submit" value="Login" />
</>
)}
}
const Glossary = ({items}) => {
return (
<>
{items.map(item => (
// Without the key, React will fire a key warning
<React.Fragment key={item.id}>
<dt>{item.term}</dt>
<dd>{item.description}</dd>
</React.Fragment>
))}
</>
);
}
React fragments are a bit faster and have little lesser memory consumption (lesser DOM nodes). This is helpful in applications with deep tree structures.
Styling can be easier at times since there is no additional div created. Sometimes some libraries depend on parent-child relationships, and the div in the middle causes layout issues.
The DOM is easier to inspect because of less clutter.