Hello World
React · Reference cheat sheet
Hello World
React · Reference cheat sheet
📋 Overview
React Hello World is a component that returns a simple element (often an <h1>). Once it appears in the browser via your app’s root render, your toolchain is working.
🔧 Core concepts
| Piece | Role |
|---|---|
| Root | createRoot(...).render(<App />) mounts React |
App | Top-level component |
return (...) | JSX describing UI |
| Export | Makes the component importable |
In Vite, main.jsx mounts <App /> into #root.
💡 Examples
Minimal App:
export default function App() {
return <h1>Hello, World!</h1>;
}With a child component:
function Hello() {
return <h1>Hello, World!</h1>;
}
export default function App() {
return (
<div>
<Hello />
<p>Welcome to React.</p>
</div>
);
}Mount (Vite-style main.jsx):
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import App from "./App.jsx";
createRoot(document.getElementById("root")).render(
<StrictMode>
<App />
</StrictMode>
);Expression in JSX:
const name = "Ada";
export default function App() {
return <h1>Hello, {name}!</h1>;
}⚠️ Pitfalls
getElementById("root")must match an element inindex.html.- Returning two sibling elements needs a wrapper or fragment (
<>...</>). classin JSX is writtenclassName.- Browser console errors are your friend — read the first red message carefully.