Setting Up Your First App
Before we learn how to install React on your computer, letโs see what React actually does inside a standard webpage.
Most tutorials start with a "Black Box" of 1,000 files. At CodeHarborHub, we want you to see the "Engine" first.
Now that you know why we use React, itโs time to actually build one!
In the past, setting up React was a headache. Today, we use a tool called Vite (pronounced "veet," which is French for "fast"). It sets up the folders, the server, and the tools you need in about 10 seconds.
Step 1: The Pre-Requisitesโ
To run React on your computer, you must have Node.js installed.
- Check it: Open your terminal and type
node -v. - Don't have it? Download the LTS Version from nodejs.org.
Step 2: Creating the Projectโ
Open your terminal in the folder where you want to keep your projects and run this "Magic Command":
npm create vite@latest my-react-app -- --template react
What happens next?โ
-
Navigate into the folder:
cd my-react-app -
Install the "Ingredients":
npm install -
Start the Engine:
npm run dev
๐ Success! Your terminal will give you a link (usually http://localhost:5173). Open it in your browser to see your brand new React app running!
Step 3: Understanding the "Big Three" Filesโ
When you open your new project in VS Code, you will see many files. Don't be overwhelmed! Beginners only need to care about these three:
index.html: The "Skeleton." This is the only HTML file in your project. It has one empty<div>with an ID ofroot.main.jsx: The "Bridge." This file connects your React code to thatrootdiv in the HTML.App.jsx: The "Heart." This is where you will spend 90% of your time. It is your main component.
The "Hello World" Testโ
Let's make sure everything is working.
- Open
App.jsx. - Delete everything inside the file.
- Type this simple code:
function App() {
return (
<div>
<h1>Hello CodeHarborHub! ๐</h1>
<p>My first React app is officially alive.</p>
</div>
);
}
export default App;
Check your browser at http://localhost:5173. If you see your message, congratulations! You are officially a React Developer.
You might see older tutorials mention create-react-app (CRA). While it was popular for years, it is now considered outdated and slow.
At CodeHarborHub, we use Vite because it is the professional standard for 2024 and beyond. It provides a much faster and smoother experience for developers.
๐ Ready to build? For a complete, step-by-step walkthrough on installing Node.js and initializing your project, check out our Detailed Guide to Creating Your First React App.
Summary Checklistโ
- I have Node.js installed on my machine.
- I created a project using the Vite template.
- I know that
App.jsxis the main file I need to edit. - My local development server is running.
Keep your terminal open while you code! Every time you press Save (Ctrl+S) in VS Code, Vite will automatically refresh your browser instantly. This is called Hot Module Replacement (HMR).