React09 – Forms with components

React08 – Forms

Below is a simple example of using a React form:

App.jsx:

FormSubmitChange.jsx:

React07 – Lists

In React, you must define the key inside at least the «li» elements. This is done to make the Virtual DOM more efficient.

App.jsx

FruitList.jx

Each key must be unique

React conditionals

App.jsx:

Component.jsx:

TurnOff.jsx

TurnOn.jsx:

React05 – Events

main.jsx

App.jsx:

Component.jsx

Component.jsx

Component.jsx:

React04 – Props

A name will be passed to the HelloWorld component:

In order for the HelloWorld application to receive the passed value, the following changes will need to be made:

Your browser window will look like this:

First define the constant that will contain the values. Finally, this constant is passed through a parameter called info.

The receiver of the object will access its values as follows:

The result will be as follows:

Sometimes we are only interested in a few properties from all the ones sent to us.

App.jsx

HelloWorld.jsx

Another project is created

App.jsx

Parents.jsx

Son.jsx

Daughter.jsx

React03 – First component

A new project will be created:

It will then ask you for a proyect name . If you want, name it react03.

Inside the src folder, create the components folder. Then, create the HelloWorld.jsx file with the following contents:

The component that was just created will be used in the App.jsx file:

In your browser you will see the following screen:

The following structure remains in your project:

React02

You can now delete the following files:

App.css and index.css

Some lines are deleted from the main.jsx file:

Some lines are deleted from the App.jsx:

The index.html file would be reduced to the following:

We already have our basic structure to start a project

React01

Check if you have Node.js and npm installed:

node -v
npm -v

If you don’t have them installed yet, run the following commands:

sudo apt update
sudo apt install nodejs npm -y

Run the following command to create a new project (answer the questions that the wizard will ask you):

npm create vite@latest react01

After selecting React and JavaScript, the following text will appear:

If you hold down the CTRL key and click on the link, an image similar to the one in the screenshot below will appear in your browser:

Inside the react01 folder, type the command «code .» (You will need to have Visual Studio Code installed)