Introduction
React is a very popular JavaScript library for developing modern and responsive user interfaces. With this tutorial you will learn how to create a simple web app using React.
Step 1: Preparing the development environment
Make sure you have Node.js installed on your system.
Open terminal and type the following command to create a new React app:
npx create-react-app my-app
Step 2: Project structure
Once the command has finished executing, enter your project directory:
cd my-app
Open the project in your favorite code editor. You will see an automatically generated directory structure.
Step 3: React Components
In the src
directory, you will find a file called App.js
. This is the core component of your app. You can edit this file to create your own interface.
import React from 'react';
function App() {
return (
<div>
<h1>Ciao, mondo!</h1>
</div>
);
}
export default App;
Step 4: Rendering the component
In the src/index.js
file, you will find the following code:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
This code renders the App
component within the element with the id "root" in your HTML file.
Step 5: Running the app
You can now run your React app. In the terminal, run the following command:
npm start
A local development server will start and your app will open in your default browser at http://localhost:3000
.
Step 6: Customize the web app
Now you can start customizing your web app. Edit the App
component in the src/App.js
file to add new elements or styles.
import React from 'react';
function App() {
return (
<div>
<h1>Ciao, mondo!</h1>
<p>Benvenuto nella mia web app React.</p>
</div>
);
}
export default App;
Every time you save the changes, the development server will automatically update and you will see the changes in your app.
This is just an introductory tutorial to get you started with React. You can continue to explore and learn new features, such as state management, class components, API calls, and more.
Conclusion
In this tutorial we have seen how to create a web app using the React framework. Have fun developing your own React web app!