react1
react1
Setting Up React
To start using React, you need to set up a development environment.
The easiest way to get started is by using Create React App.
Download Node.js
Create a React App: Open your terminal or command prompt and run the
following command:
bash
Copier le code
npx create-react-app my-app
This will create a new directory called my-app and set up all the
necessary files for a React project.
bash
Copier le code
cd my-app
Start the development server:
bash
Copier le code
npm start
This will start a development server and open the React application in
your browser at http://localhost:3000.
arduino
Copier le code
my-app/
├── node_modules/
├── public/
│ ├── index.html
│ └── ...
└── src/
├── App.js
├── index.js
└── ...
index.html (in the public/ folder): This is the basic HTML template
where React injects the app. It contains a <div id="root"></div>
element where the React components are rendered.
App.js: This is the main React component where you can start writing
your application.
index.js: This is the entry point for your React app. It renders the
App component into the root element.
3. Components in React
React components are the building blocks of your UI. There are two
types of components: Functional Components and Class Components.
function App() {
return (
<div>
<h1>Hello, React!</h1>
</div>
);
}
jsx
Copier le code
const element = <h1>Hello, World!</h1>;