React powers a huge number of modern web apps, but the ecosystem can feel overwhelming when you are just starting out. This quickstart focuses on the absolute essentials: getting a project running, understanding the core ideas, and building a tiny interactive component so you can see React in action.
You do not need prior React experience. Basic HTML, CSS, and JavaScript familiarity will help, but each step includes a short explanation so you can follow along.
React is a JavaScript library for building user interfaces. Instead of manually updating the DOM with document.getElementById(...) calls, you describe what the UI should look like for a given state, and React updates the page for you when that state changes.
Key ideas:
Once you understand these four concepts, you can go surprisingly far with React.
Before you start, make sure you have:
To check Node and npm:
node -v
npm -v
If those commands fail, install Node from https://nodejs.org/.
The easiest way to get started today is to use Vite, a fast build tool that scaffolds a React project for you.
In a terminal:
# 1. Create a new Vite + React project
npm create vite@latest my-react-app -- --template react
# 2. Move into the project folder
cd my-react-app
# 3. Install dependencies
npm install
# 4. Start the dev server
npm run dev
Open the URL printed in the terminal (usually http://localhost:5173). You should see the default Vite + React starter page.
If the dev server fails to start, carefully read the error message in the terminal. Common fixes include closing other processes using the same port or reinstalling dependencies with rm -rf node_modules package-lock.json && npm install on macOS/Linux.
Open the my-react-app folder in your editor and look for these files:
index.html – the main HTML file.src/main.jsx – the entry point where React is attached to the page.src/App.jsx – the main React component you see in the browser.Open src/main.jsx. You should see something similar to:
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.jsx";
ReactDOM.createRoot(document.getElementById("root")).render(
<React.StrictMode>
<App />
</React.StrictMode>
);
This code tells React: “Find the element with id root in index.html and render the App component inside it.”
Now open src/App.jsx and replace its contents with a very simple component:
function App() {
return (
<div>
<h1>Mastering React: A Beginner's Guide</h1>
<p>Welcome to your first React component!</p>
</div>
);
}
export default App;
Save the file. Your browser should automatically refresh and show the new heading and paragraph. That is a React component in action.
The return block above looks like HTML, but it is actually JSX. Under the hood, JSX is compiled into regular JavaScript. A couple of small differences from HTML:
className instead of class.{} to insert JavaScript values.Example:
const name = "Ada";
function Greeting() {
return <p>Hello, {name}!</p>;
}
Static text is nice, but React shines when your UI reacts to user actions. Let’s build a simple counter using state.
Update src/App.jsx:
import { useState } from "react";
function App() {
const [count, setCount] = useState(0);
return (
<div>
<h1>React Counter</h1>
<p>Current count: {count}</p>
<button onClick={() => setCount(count + 1)}>Increment</button>
</div>
);
}
export default App;
What is happening here?
useState(0) creates a piece of state named count, starting at 0.setCount is a function you call to update that state.setCount(count + 1) runs; React updates count and re-renders the component, so the text on the page changes.Try clicking the button several times and watch the count update.
As your UI grows, you will want to split it into smaller, focused components.
Create a new file src/Counter.jsx:
import { useState } from "react";
function Counter({ label }) {
const [value, setValue] = useState(0);
return (
<div>
<h2>{label}</h2>
<p>Value: {value}</p>
<button onClick={() => setValue(value + 1)}>+1</button>
</div>
);
}
export default Counter;
Now update src/App.jsx to use this new component:
import Counter from "./Counter.jsx";
function App() {
return (
<div>
<h1>React Components</h1>
<Counter label="First counter" />
<Counter label="Second counter" />
</div>
);
}
export default App;
Here you are passing a prop (label) into each Counter. Each instance maintains its own state (value), but they share the same component logic.
At this point you have:
useState.To keep learning React, consider exploring:
react-router.Most importantly, build something small but real: a todo list, a notes app, or a simple dashboard. The more you practice, the more natural React will feel.
If you run into issues:
ReactDOM.createRoot(...).render(<App />) in main.jsx refers to an element with id="root" in index.html.npm run dev.node_modules and lock files (package-lock.json or yarn.lock) and reinstall dependencies.<div> or <>...</> fragment).Use these errors as learning opportunities—reading and solving them is a big part of mastering React.
Questions? Open an issue or join our discussions