Republic of Developers
JavaScript-Interview-Questions-and-Answers
JavaScript Interview Questions and Answers (Part-1)
January 29, 2025
HTML Attributes Every Developer Should Know
HTML Attributes Every Developer Should Know
January 27, 2025
Top-10-VS-Code-Extensions-for-Web-Development
Top 10 VS Code Extensions for Web Development
December 6, 2024
Top-10-Chrome-Extensions-for-Developers
Top 10 Chrome Extensions for Developers
September 26, 2024
JavaScript-Best-Practices
JavaScript Best Practices
September 24, 2024
Republic of Developers

Type and hit Enter to search

  • Home
  • Blog
  • Contact US
Republic of Developers
  • Home
  • Blog
  • Contact US
How to Create a React JS app with CRA

How to Create a React JS app with create-react-app?

ROD Team
ROD Team
October 9, 2023
3
453 Views
2 Comments

In this article, you will learn how to create a React application using create-react-app (CRA). There are also other ways to create React applications but here we are using CRA.

Step 1: Setup Your Development Environment

Before starting to build the React app, you need to ensure that your development environment is properly set up. Here’s what you’ll need:

1.1) Node.js

Make sure you have Node installed on your machine. You can download it from the official Node.js website. CRA requires a Node version of at least 10.

Note: You can check the version of the Node by running the below command in your Command Prompt:

node -v

1.2) NPM (Node Package Manager)

It is included in the installation of Node. You need the version of npm should be at least 5.2.

Note: You can check the version of NPM by running the below command:

npm -v

1.3) Text Editor or IDE

Choose a good text editor or integrated development environment (IDE) to write your code. I recommend Visual Studio Code. You can download it at code.visualstudio.com.

Step 2: Create a New React App

To create a new React app, open the directory in which you want to create an app in Visual Studio Code. Then open your terminal (in VSCode, go to View > Terminal) and run the following command:

npx create-react-app my-react-app
1_create-react-app

Replace “my-react-app” with the name you want for your app. This command will create a new directory with the specified name and set up a basic React project structure.

Step 3: Explore the Project Structure

Navigate to the newly created app directory using the terminal:

cd my-react-app

Here, you’ll find the basic structure of your React app as shown in the below image:

2_folder-structure

src: This directory contains the main source code of your app.
public: Static assets like HTML files, images, etc., go here.
package.json: Configuration and dependencies for your app.
App.js: The main React component.

Step 4: Run the App Locally

To see your app in action, run the following command in your terminal (in VSCode, go to View > Terminal):

npm start
3_start-app

This command starts the development server and automatically reflects any changes made to the code in the web browser. The development server will start on the http://localhost:3000/.

You can see the default page for our app as shown in the below image:

4_app-ui

Step 5: Update the App Component

Let’s change something on the default page. Open the App.js file it contains the below code:

import logo from './logo.svg';
import './App.css';

function App() {
  return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        <p>
          Edit <code>src/App.js</code> and save to reload.
        </p>
        <a className="App-link" href="https://reactjs.org" target="_blank" rel="noopener noreferrer">
          Learn React
        </a>
      </header>
    </div>
  );
}

export default App;

In the App component remove the “p” and “a” tags, and add an “h1” element with the name of our project, “My React App”.

import logo from './logo.svg';
import './App.css';

function App() {
  return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        <h1>My React App</h1>
      </header>
    </div>
  );
}

export default App;

When you save (Ctrl + S), you will see our page automatically update to look like this:

4.1_updated-app-ui

Summary

In this article, we learned how to create a single-page React application using create-react-app (CRA). We also covered React JS prerequisites and application folder structure.

Your input matters- comment your thoughts!☻

Categories:

React

Other Articles

How-to-Add-Metadata-in-React
Previous

How to Add Metadata in React

React Fundamentals
Next

React Fundamentals

2 Comments

  1. Tejas says:
    October 9, 2023 at 1:45 pm

    Good explanation!!!

    Reply
    1. ROD Team ROD Team says:
      October 9, 2023 at 6:22 pm

      Thanks tejas!!

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Posts

How-to-pass-data-from-parent-to-child-components-in-ReactJS

How to pass data from parent to child components in React?

December 7, 2023
React Fundamentals

React Fundamentals

November 24, 2023
How-to-Add-Metadata-in-React

How to Add Metadata in React

August 18, 2023
How-to-Secure-Query-Strings-in-React

How to Secure Query Strings in React

August 11, 2023
Republic of Developers

Republic of Developers provides easy-to-follow tutorials on SharePoint, Power Apps, Power BI, JavaScript, React JS, PHP, and more. Improve your coding skills and stay updated in the ever-changing tech world.

Republic of Developer © , All Rights Reserved.

Page Links

  • Home
  • Blog
  • Contact US
  • Site map

Category

  • React
  • SharePoint
  • JavaScript

Follow Us

Instagram Linkedin
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT