0% found this document useful (0 votes)
33 views

react1

Uploaded by

3q8ax
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

react1

Uploaded by

3q8ax
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

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.

Using Create React App:


Install Node.js: React requires Node.js and npm (node package manager)
to manage packages.

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.

Navigate to your app directory:

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.

2. Understanding React Structure


When you create a React app with create-react-app, you'll see the
following folder structure:

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.

Functional Component Example:


javascript
Copier le code
// src/App.js
import React from 'react';

function App() {
return (
<div>
<h1>Hello, React!</h1>
</div>
);
}

export default App;


This is a functional component which is a JavaScript function that
returns JSX (a syntax extension for JavaScript).
Class Component Example:
javascript
Copier le code
// src/App.js
import React, { Component } from 'react';

class App extends Component {


render() {
return (
<div>
<h1>Hello, React!</h1>
</div>
);
}
}

export default App;


This is a class component, which extends React.Component and requires
a render() method.
JSX (JavaScript XML):
JSX allows you to write HTML-like syntax directly within your
JavaScript code. It's not required to use JSX, but it makes React
development easier.

jsx
Copier le code
const element = <h1>Hello, World!</h1>;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy