Home > Web Front-end > JS Tutorial > How to Create a React App

How to Create a React App

Mary-Kate Olsen
Release: 2024-12-15 21:11:10
Original
137 people have browsed it

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:

    • Download and install Node.js (npm is included with Node.js).
    • Verify installation:
     node -v
     npm -v
    
    Copy after login
    Copy after login
  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
Copy after login
Copy after login

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
Copy after login
  1. Create the React App: Replace todolist with your desired project name:
   npx create-react-app todolist
Copy after login
  • This command creates a new folder (todolist) with all the necessary files and dependencies.

How to Create a React App

How to Create a React App

  1. Navigate into the Project Folder:
   cd todolist
Copy after login

Step 3: Start the Development Server

Run the following command to launch the development server:

npm start
Copy after login

How to Create a React App

  • 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.

How to Create a React App

Step 4: Explore the Project Structure

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

 node -v
 npm -v
Copy after login
Copy after login

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:
  npm install -g create-react-app
Copy after login
Copy after login
  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!

The above is the detailed content of How to Create a React App. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template