Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Structure of a React Project | React in Practice
Introduction to React

Structure of a React Project

If we look at the project folder, we will find the following files:

Pict

The only files of folders that are relevant at this point are:

  • node_modules contains all the installed modules;
  • public contains the main index.html file and other files related to it;
  • src contains a basic template for the HTML page;
  • package.json and package-lock contain data related to the project, the installed modules, and their versions.

We need to start our work by deleting all the files from the src and public folders.

Create an index.html file in the public folder and add the following code:

html

index.html

css

index.css

js

index.js

Create an index.js file and add the following code inside it:

In the index.js file, we import React and ReactDOM to use the React functions.

Note that we don't need to manually import index.js in index.html: it is automatically done for us when we run the application.

We can use the DOM in this script to access the root element from the HTML document and create a root object to render React components. It is done in the second-last line as follows:

In the last line, we use the created React root object to render the Main component, which represents a React component. We will learn more about React components in the next section.

Following is what the output should look like for the above setup:

Everything was clear?

Section 3. Chapter 4
course content

Course Content

Introduction to React

Structure of a React Project

If we look at the project folder, we will find the following files:

Pict

The only files of folders that are relevant at this point are:

  • node_modules contains all the installed modules;
  • public contains the main index.html file and other files related to it;
  • src contains a basic template for the HTML page;
  • package.json and package-lock contain data related to the project, the installed modules, and their versions.

We need to start our work by deleting all the files from the src and public folders.

Create an index.html file in the public folder and add the following code:

html

index.html

css

index.css

js

index.js

Create an index.js file and add the following code inside it:

In the index.js file, we import React and ReactDOM to use the React functions.

Note that we don't need to manually import index.js in index.html: it is automatically done for us when we run the application.

We can use the DOM in this script to access the root element from the HTML document and create a root object to render React components. It is done in the second-last line as follows:

In the last line, we use the created React root object to render the Main component, which represents a React component. We will learn more about React components in the next section.

Following is what the output should look like for the above setup:

Everything was clear?

Section 3. Chapter 4
some-alt