Skip to content
Justice Tech School

Fragments and Rendering

A component returns one root. Wrap siblings in a fragment <> </> to avoid extra divs. createRoot attaches your app to the page.

Example
import { createRoot } from 'react-dom/client';

function App() {
  return (
    <>
      <h1>Title</h1>
      <p>Text</p>
    </>
  );
}
createRoot(document.getElementById('root')).render(<App />);

Exercise

Mount the app.

createRoot(el).(<App />)

Quiz Test

What does a fragment avoid?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.