Create new react
Here are the steps to create a new React project:
Using Create React App
Create React App is a tool provided by Facebook that allows you to quickly create a new React project with a minimal setup.
- Open your terminal or command prompt.
- Run the following command:
npx create-react-app my-app
(replace "my-app" with your desired app name). - Follow the prompts to set up your project. You'll be asked to choose a template (e.g., "typescript" or "javascript") and whether you want to use a specific version of React.
- Once the setup is complete, navigate to your project directory:
cd my-app
. - Start the development server:
npm start
(oryarn start
if you're using Yarn). - Open your web browser and navigate to
http://localhost:3000
to see your new React app in action.
Using a Code Editor or IDE
If you prefer to create a new React project from scratch, you can use a code editor or IDE like Visual Studio Code, IntelliJ IDEA, or Sublime Text.
- Create a new folder for your project and navigate to it in your terminal or command prompt.
- Initialize a new Node.js project by running
npm init
(oryarn init
if you're using Yarn). - Install React and its dependencies by running
npm install react react-dom
(oryarn add react react-dom
if you're using Yarn). - Create a new file called
index.js
and add the following code:import React from 'react'; import ReactDOM from 'react-dom';
const App = () => { return
Hello, World!
; };ReactDOM.render(
5. Create a new file called `index.html` and add the following code:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>My React App</title>
</head>
<body>
<div id="root"></div>
<script src="index.js"></script>
</body>
</html>
- Start the development server by running
npm start
(oryarn start
if you're using Yarn). - Open your web browser and navigate to
http://localhost:3000
to see your new React app in action.
That's it! You now have a new React project up and running.