Mount an App with createRoot
Mount the first component
Mounting means connecting a React tree to a place in an existing browser document. For a new client-rendered page, createRoot from react-dom/client creates a React root for a DOM element. Calling render on that root requests display of a React element. This is the startup code for the HTML shell from the previous lesson.
export default function App() { return ( <main> <h1>Desk planner</h1> <p>Today: organize your notes.</p> </main> );}App is a function component: it describes a main content area containing a heading and a paragraph. The default export allows the entry module to import it without braces. The angle-bracket notation is JSX; the React plugin handles its transformation. Chapter 4 explains JSX syntax in depth.
import { createRoot } from 'react-dom/client';import App from './App.jsx';
const container = document.getElementById('root');if (!container) { throw new Error('Missing root element');}const root = createRoot(container);root.render(<App />);getElementById finds the div defined in index.html. The guard stops startup with a useful error if the div is absent. createRoot returns a root object. render receives the element described by <App />. When the initial render commits successfully, the expected page heading is Desk planner and the paragraph is Today: organize your notes. The call is not a guarantee that the DOM has already updated by the very next JavaScript statement.
A small variation
export default function App() { return <h1>Notes ready</h1>;}With the same entry module, the expected heading becomes Notes ready. No new root is required for ordinary component updates. In a development server with compatible hot updates, an edit may update the page without a manual reload; otherwise reload after saving. This is a predicted result, not a recorded browser test.
Troubleshoot a blank page
First inspect the development terminal and browser console. Confirm index.html loads the correct entry, imports resolve, the ID matches the HTML, and render is called with <App />, not the App function itself. Creating a root without rendering does not display a component. Keep one root for this single app. If the HTML already contains React-generated server markup, use the appropriate hydration API instead; server rendering is outside this chapter.
Practice
Use the fixture to diagnose a mismatch between a new container ID and the entry module. Then change the visible heading without changing the root. Browser verification is a manual, staged activity until dependencies are approved.