DEV Community

Cover image for How to Create a React App
Agbo, Daniel Onuoha
Agbo, Daniel Onuoha

Posted on • Edited on

2

How to Create a React App

React is a powerful JavaScript library for building user interfaces, developed by Facebook. It simplifies the process of creating dynamic, interactive web applications. This guide will walk you through creating a React application from scratch.

Prerequisites

Before you start, ensure you have the following installed on your system:

  1. Node.js and npm:

     node -v
     npm -v
    
  2. Text Editor:

    Use any code editor you choose, such as Visual Studio Code.

Step 1: Install create-react-app

create-react-app is an official tool by the React team to quickly set up a new React project with a good default configuration.

  • Open your terminal or command prompt and install create-react-app globally:
  npm install -g create-react-app
Enter fullscreen mode Exit fullscreen mode

Step 2: Create a New React App

  1. Navigate to Your Project Directory: Choose where you want your project to reside. For example:
   cd Desktop
Enter fullscreen mode Exit fullscreen mode
  1. Create the React App: Replace todolist with your desired project name:
   npx create-react-app todolist
Enter fullscreen mode Exit fullscreen mode
  • This command creates a new folder (todolist) with all the necessary files and dependencies.

cra react app

cra finished

  1. Navigate into the Project Folder:
   cd todolist
Enter fullscreen mode Exit fullscreen mode

Step 3: Start the Development Server

Run the following command to launch the development server:

npm start
Enter fullscreen mode Exit fullscreen mode

npm start

  • Your default browser should open automatically, displaying the React app at http://localhost:3000.
  • If it doesn’t, manually open your browser and go to that address.

Image description

Step 4: Explore the Project Structure

Here's an overview of the files and folders created by create-react-app:

todolist/
├── node_modules/
├── public/
│   ├── index.html       // Main HTML file
├── src/
│   ├── App.js           // Main React component
│   ├── index.js         // Entry point for the React app
│   └── App.css          // Styling for the App component
├── .gitignore
├── package.json         // Project metadata and dependencies
└── README.md
Enter fullscreen mode Exit fullscreen mode

Step 5: Modify Your React App

  1. Edit the Main Component (App.js): Open src/App.js in your text editor and customize the JSX to change the content:
   function App() {
     return (
       <div className="App">
         <h1>Hello, React!</h1>
       </div>
     );
   }

   export default App;
Enter fullscreen mode Exit fullscreen mode
  1. Save Changes and See Updates: After saving, the browser automatically refreshes to reflect your changes.

Conclusion

Congratulations! You've successfully created and run your first React app. This setup provides a solid foundation for building powerful, component-based web applications. Explore React components, state management, and hooks to enhance your skills further!

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs