How to Create Your First React Project: A Beginner’s Guide

Adeel HussainAdeel Hussain
3 min read

If you’re diving into the world of React, you’re in for a treat. React makes building interactive user interfaces smooth, and it’s one of the most popular JavaScript libraries used by developers today.

In this guide, we’ll walk you through the process of setting up your very first React project. By the end, you'll have a simple React app running on your computer and a better understanding of how React works.

Step 1: Prerequisites

Before we dive into React, make sure you have the following:

  1. Node.js: React relies on Node.js to run. You can check if you have it installed by running node -v in your terminal.

    • Download and install Node.js from here.
  2. npm (Node Package Manager): npm comes bundled with Node.js and will help us install the packages we need for our React app.

Step 2: Create Your React Project Using npx

React’s official CLI tool, Create React App, now recommends using npx to create your project. npx is a package runner that allows you to execute commands without installing them globally.

  1. Open your terminal or command prompt.

  2. Run the following command (replace my-react-app with your preferred project name):

npx create-react-app my-react-app

This command will download the latest version of Create React App and set up the project for you, without needing to install anything globally. It will take a minute or two to install all the necessary dependencies.

Step 3: Navigate into Your Project Directory

Once your project is created, let's navigate into your project folder to see the files.

cd my-react-app

Step 4: Start the Development Server

Now, let's run the React app to see it in action.

  1. In your terminal, run:
npm start

This will open up a new tab in your browser with the address http://localhost:3000/. You’ll see a default React page that says "Edit src/App.js and save to reload." Congrats! You’ve just created your first React project.

Step 5: Explore Your Project Structure

Let’s take a quick look at the key files and folders in your project:

  • public/index.html: The main HTML file that will load your React app.

  • src/App.js: The JavaScript file where the main app component lives. This is where we’ll be working most of the time.

  • src/index.js: The entry point for your app. It renders the App component to the DOM.

Step 6: Make Your First Change

Now, let’s make your app a little more personal by changing the text on the page.

  1. Open src/App.js in your code editor.

  2. Replace the existing code with the following:

import React from 'react';
import './App.css';

function App() {
  return (
    <div className="App">
      <h1>Welcome to My First React App!</h1>
      <p>This is the start of your React journey!</p>
    </div>
  );
}

export default App;
  1. Save the file, and go back to your browser. You’ll see the page refresh with the new message!

Step 7: Next Steps

Now that you have your first React project up and running, here are a few ideas on what to do next:

  • Learn about Components: React is all about components. You’ll be working with functional or class components to build your app.

  • State and Props: These are essential concepts in React that allow you to make your app interactive and dynamic.

  • React Router: If you want to add multiple pages to your app, React Router is a great tool to manage navigation.

Conclusion

Congrats on creating your first React project! Now that you have the basics down, you can start exploring more advanced concepts, building more complex apps, and experimenting with different libraries and tools in the React ecosystem.

Remember, React is all about breaking things down into smaller, reusable components — the more you practice, the better you’ll get.

Happy coding, and welcome to the world of React! 🚀

0
Subscribe to my newsletter

Read articles from Adeel Hussain directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Adeel Hussain
Adeel Hussain