Example 1 — Hello, React!
<div id="root"></div>
<script type="text/babel">
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<h1>Hello, React!</h1>);
</script>
This page is a self-contained introduction to React—a JavaScript library for building interactive user interfaces. You will understand what React is, how components and JSX work, and why teams choose React for modern front-end apps.
Library overview.
Reusable UI.
Key benefits.
Meta & MIT.
Syntax & updates.
Hands-on code.
React is a declarative, efficient, and flexible front-end JavaScript library for creating user interfaces using UI components. Instead of manually updating the DOM every time data changes, you describe what the UI should look like—React figures out the minimal updates needed.
React powers single-page applications, dashboards, mobile apps (via React Native), and static sites. Companies such as Meta, Netflix, Airbnb, and Discord use React in production.
Learn JavaScript fundamentals first. React builds on functions, objects, and arrays—you will use all three inside every component.
React components are small, isolated pieces of code that help you compose complex UIs from simple building blocks. A component is usually a JavaScript function that returns JSX describing what to render.
For example, if you build a Button component once, you can reuse it anywhere in your project to generate a button without rewriting the same markup and styles each time. Nest components inside one another to build pages: App → Header → NavItem.
function Button({ label }) {
return <button type="button">{label}</button>;
}
// Reuse anywhere:
// <Button label="Save" />
// <Button label="Cancel" />Many JavaScript tools exist for front-end work—Angular, Vue, Svelte, jQuery, and plain DOM APIs. So why choose React?
React is a library (not a full framework) focused on the view layer. It promotes reusable UI components that display data that changes over time. When user input or server data updates, React re-renders only what changed—keeping apps fast and predictable.
React is a free and open-source front-end JavaScript library developed by Meta and the open-source community under the MIT License.
Jordan Walke is recognized as the original author of React. It was first deployed on Facebook’s news feed in 2011 and open-sourced at JSConf US in 2013. Today React follows semantic versioning with frequent improvements to hooks, server components, and developer tooling.
Have a quick look at React at a glance:
| Developer(s) | Meta and community |
|---|---|
| License | MIT License |
| Original author | Jordan Walke |
| Platform | Web platform (browser); React Native for mobile |
| First release | 2013 (open source) |
| Written in | JavaScript |
JSX (JavaScript XML) lets you write HTML-like tags inside JavaScript. It is not required, but almost every React project uses it because it keeps structure readable.
const element = <h1>Hello, {name}!</h1>;
// JSX compiles to:
// React.createElement('h1', null, 'Hello, ', name, '!');{expression} to embed JavaScript values<>fragment</>className instead of class for CSS classes<img /> and <br />The browser DOM is slow to change when you touch many nodes. React keeps a lightweight virtual DOM tree in memory—a JavaScript representation of your UI.
When state or props change, React builds a new virtual tree, compares (diffs) it with the previous one, and updates only the real DOM nodes that actually changed. That batching keeps interfaces responsive even with frequent data updates.
For real apps, use a build tool. Vite is fast and widely used in 2026:
npm create vite@latest my-react-app -- --template react
cd my-react-app
npm install
npm run devFor quick experiments without installing Node.js, load React from a CDN:
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script type="text/babel">
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<h1>Hello, React!</h1>);
</script>The following are some of the most significant advantages of using React in your project:
React is powerful, but weigh these trade-offs before adopting it everywhere:
| Concept | What it does |
|---|---|
| Components | Functions or classes that return UI |
| JSX | Markup syntax inside JavaScript |
| Props | Read-only inputs passed from parent to child |
| State | Data that changes over time (useState, useReducer) |
| Hooks | Functions like useEffect for side effects in function components |
| Virtual DOM | In-memory UI tree for efficient updates |
| Event handling | onClick, onChange with camelCase props |
| Task | Example |
|---|---|
| Render app | root.render(<App />); |
| Component | function Card() { return <div />; } |
| Props | <Welcome name="Alex" /> |
| State | const [n, setN] = useState(0); |
| List render | {items.map(i => <li key={i.id}>{i.text}</li>)} |
| Effect | useEffect(() => { ... }, []); |
Five starter demos. Use View Output to preview here, or open Try It Yourself to edit and run React in the browser editor (CDN + Babel).
<div id="root"></div>
<script type="text/babel">
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<h1>Hello, React!</h1>);
</script>function Greeting() {
return (
<div>
<h1>Welcome to React</h1>
<p>Components are reusable pieces of UI.</p>
</div>
);
}
root.render(<Greeting />);function Welcome({ name }) {
return <h1>Hello, {name}!</h1>;
}
function App() {
return (
<div>
<Welcome name="Alex" />
<Welcome name="Sam" />
</div>
);
}const { useState } = React;
function Counter() {
const [count, setCount] = useState(0);
return (
<div>
<p>Count: {count}</p>
<button type="button" onClick={() => setCount(count + 1)}>
Increment
</button>
</div>
);
}function TodoList() {
const tasks = ['Learn JSX', 'Build a component', 'Add state'];
return (
<ul>
{tasks.map((task) => (
<li key={task}>{task}</li>
))}
</ul>
);
}| Task | React | Vanilla JS |
|---|---|---|
| Update text | Change state; React re-renders | element.textContent = '...' |
| Reusable UI | <Button /> component | Copy HTML or template strings |
| List of items | items.map(...) in JSX | Loop + createElement or innerHTML |
| Complex apps | Component tree + hooks | Manual DOM sync gets fragile |
User clicks a button, or fetch loads new JSON into state.
React calls your component functions with new props/state.
React compares the new tree with the previous one.
Only changed nodes update on screen—fast, interactive UI.
key when rendering listskey when list order changesReact’s influence goes far beyond the web. Ideas pioneered in React—components, declarative UI, and a virtual DOM diff—inspired frameworks like Vue and influenced how browsers and standards evolve. React Native brings the same component model to mobile apps used by Meta, Microsoft, and many startups.
Edit any example from this page in the live Try It editor.
11 people found this page helpful