Introduction to React
Component-based UI — why React, how it works, your first element
Skills taught: react.components, react.virtual-dom, react.render, react.elements
Your first React component
// React 18 — function component
function App() {
return (
<div>
<h1>Hello, React!</h1>
<p>This is a React component.</p>
</div>
);
}
// Mount the app
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);
// Components are just functions that return JSX
function Greeting({ name }) {
return <h2>Hello, {name}!</h2>;
}
function Card({ title, body }) {
return (
<div style={{ border: '1px solid #ccc', padding: '12px', borderRadius: '8px' }}>
<h3>{title}</h3>
<p>{body}</p>
</div>
);
}
// Compose components inside other components
function App() {
return (
<div>
<Greeting name="Alice" />
<Greeting name="Bob" />
<Card
title="React 18"
body="Build UIs with components."
/>
</div>
);
}
Tip: React component names MUST start with a capital letter. `` is treated as an HTML tag; `` is treated as a React component.
Frequently Asked Questions
Does React replace HTML and CSS?
No. React renders HTML elements and you still write CSS. JSX looks like HTML but compiles to JavaScript. React adds a component model and state management on top of the same HTML/CSS you already know. You can use plain CSS files, CSS modules, or CSS-in-JS libraries alongside React.