Setting Up React
Alright, let's get our hands dirty! Setting up a React project used to be a headache with all the webpack and babel configuration. But now, it's as easy as running a single command. No more wrestling with build tools - we'll let Create React App handle the heavy lifting.
Create React App is Facebook's official tool for starting new React projects. It comes with everything pre-configured so you can focus on writing React code, not configuration files. Trust me, this saves hours of setup time.
Creating Your First Project
Open your terminal and type these two commands. The first one creates a new React project, and the second navigates into it. That's it - you now have a complete React development environment ready to go!
npx create-react-app my-first-app
cd my-first-app
Don't have npx? No worries! Just make sure you have Node.js installed (version 14 or higher). You can download it from nodejs.org. The npx command comes bundled with Node.js, so you're good to go!
Project Structure Overview
Let's peek inside our project folder. You'll see a bunch of files, but don't get overwhelmed - most of them you won't touch often. Here's what matters:
The src folder is where your React code lives. Your components, styles, and logic all go here. The public folder contains the HTML template and static assets. The package.json file lists your dependencies and scripts.
my-first-app/
├── public/
├── src/
│ ├── App.js
│ ├── index.js
│ └── App.css
├── package.json
└── README.md
Running the Development Server
Now for the exciting part - let's see our app in action! Inside your project folder, run the start script. This launches a development server with hot reloading, which means your browser auto-refreshes when you save changes. It's like having a live preview of your work!
npm start
Your default browser should open automatically and display your React app. If it doesn't, just open your browser and go to localhost:3000. You should see the default React welcome page. Congratulations - you're officially a React developer!
Try it Yourself →