Create a new react app
Here's a step-by-step guide to create a new React app:
Method 1: Using create-react-app
create-react-app
is a tool provided by Facebook that allows you to quickly create a new React app with all the necessary dependencies and configurations.
-
Open your terminal and run the following command:
npx create-react-app my-app
Replace
my-app
with the name of your app. -
Follow the prompts to choose the template and configuration options.
-
Once the installation is complete, navigate to the project directory:
cd my-app
-
Start the development server:
npm start
This will start the development server and open your app in your default web browser.
Method 2: Using react-scripts
react-scripts
is a package that provides a set of scripts for building and running a React app.
- Create a new directory for your app:
mkdir my-app
- Navigate to the directory:
cd my-app
- Initialize a new npm project:
npm init -y
- Install the necessary dependencies:
npm install react react-dom react-scripts
- Create a new file called
index.js
and add the following code:import React from 'react'; import ReactDOM from 'react-dom'; import App from './App';
ReactDOM.render(
6. Create a new file called `App.js` and add the following code:
import React from 'react';
function App() { return
Welcome to my app!
; }export default App;
7. Create a new file called `index.html` and add the following code:
<!DOCTYPE html>
That's it! You now have a new React app up and running.