Starting the ReactJS - The beginning - IndianTechnoEra
Latest update Android YouTube

Starting the ReactJS - The beginning

System Configuration, Rendering Elements, ReactDOM.render, React.StrictMode, React Development, React Application, DOM Rendering, Nov 16

When it comes to developing web applications with React, understanding the system configuration and how elements are rendered to the Document Object Model (DOM) is crucial. 

In this blog post, we will delve into the prerequisites and setup also intricacies of system configuration and rendering elements, with a focus on the ReactDOM.render method and the importance of React.StrictMode.

Deploying a Portal: A Step-by-Step Guide

In this case study, we will walk through the deployment process for the Customer Service Portal application, which is built using ReactJS. By following these steps, you'll be able to set up the application on your local machine for development and testing.

Prerequisites

Before getting started with the deployment process, ensure that you have the following prerequisites in place:

Node.js: Make sure you have Node.js installed on your machine. You can download it from the Node.js official website or obtain it from your organization's Software House if applicable.


Step 1: Download the Case Study Folder

First, you need to obtain the Customer Service Portal case study folder. You can download it from the provided link. Make sure to save it to a location on your local machine where you can easily access it.


Step 2: Installing the Required Packages

To run the Customer Service Portal application, you need to install the necessary Node.js packages. Here's how to do it:

  • Open your Node.js command prompt.
  • Navigate to the folder where you downloaded the case study.
  • Execute the command: npm install

This command will automatically install all the required packages and dependencies for the Customer Service Portal.


Step 3: Setting Up npm Proxy (If Needed)

In some cases, if your machine is connected to the Infosys network or a network with similar restrictions, the installation of npm modules might be prevented. To bypass this issue, you can configure the npm proxy settings. To do so, follow these steps:

  • Open your Node.js command prompt.
  • Execute the following command to set the proxy:
  • npm config set proxy http://your-proxy-server:your-proxy-port
  • npm config set https-proxy http://your-proxy-server:your-proxy-port

Replace your-proxy-server and your-proxy-port with the actual proxy server and port provided by your network administrator.

This step is essential for ensuring that npm can access the necessary packages.


Step 4: Install JSON Server

The Customer Service Portal interacts with a JSON server, which you need to install separately. To install the JSON server, run the following command:

npm install json-server -g

This command installs the JSON server globally on your machine.


Step 5: Start the JSON Server

The JSON server needs to be running to serve the data required by the Customer Service Portal. Open a second Node.js command prompt and navigate to the same folder where you downloaded the case study. Start the JSON server by running the following command:

json-server --watch db.json --port 4000

This command launches the JSON server and specifies that it should watch the db.json file and run on port 4000.


Step 6: Start the Application

With all the required dependencies and the JSON server in place, you can now start the Customer Service Portal application. In your original Node.js command prompt (the one used in Step 2), execute the following command:

npm start

The Customer Service Portal application will start and run on port 3000 by default.

[If not running then check global installation "npm install -g react-scripts"]


Step 7: Access the Application

Open your web browser and navigate to http://localhost:3000 to access the Customer Service Portal. You should now be able to interact with the application for development and testing purposes.

Congratulations! You've successfully deployed the Customer Service Portal case study on your local machine. You can now begin working with the application and exploring its features.

System Configuration for React Applications

Before we dive deeper into the Customer Service Portal, let's briefly discuss the system configuration required for React applications.

Create a React Application

You can create a new React application using the create-react-app tool. To do this, you have two options:

  • Use npx create-react-app my-app to create a new React application with the name "my-app." This command will generate a project structure and install the necessary dependencies.
  • Alternatively, you can use the older create-react-app package if you have it installed globally. The command would be create-react-app my-app. However, it is recommended to use the first option, which does not require a global installation.

Running the Application: Once you have created a React application, navigate to the application's folder in your terminal and run the development server with the following command:

npm start

This command starts the development server, compiles your React code, and opens the application in your default web browser. You can access the application locally at http://localhost:3000.

Now, let's explore the functionalities of the Customer Service Portal.

Customer Service Portal

The Customer Service Portal is a React-based application that provides several essential functionalities for both customers and businesses. Here's an overview of its key features:

1. Login: The Login feature allows customers to access their accounts by entering the necessary credentials. It typically involves providing a username or email address and a password. This authentication process ensures that only authorized users can access their accounts and utilize the services offered by the portal.


2. Purchased Items: The Purchased Items section displays a list of products or services that a customer has bought from the business. This section often includes details such as product names, quantities, prices, and order history. It helps customers keep track of their purchases and provides easy access to their order information.


3. Feedback: In the Feedback feature, customers have the opportunity to provide their thoughts and opinions on the products or services they've purchased. Feedback can be in the form of reviews, ratings, or comments. This functionality is valuable for both customers and businesses, as it allows customers to share their experiences and helps businesses improve their products and services based on customer input.

The Customer Service Portal leverages the power of React to create a user-friendly and responsive interface for these functionalities. It provides an efficient and enjoyable experience for customers, while also offering valuable insights and interaction opportunities for businesses.

With these features in place, the Customer Service Portal enhances the overall customer experience, fosters communication between customers and businesses, and contributes to the success of the enterprise. It's a great example of how React can be used to develop interactive and functional web applications

Know Internal Rendering

Before we dive into rendering elements to the DOM, let's take a quick look at the system configuration that sets up your React application. This configuration is generally present in the src/index.js file. It looks something like this:

ReactDOM.render(
  <React.StrictMode>

    <App />

  </React.StrictMode>,

  document.getElementById('root')
);

This snippet is the entry point of your React application, and it deserves a closer examination.

ReactDOM.render

ReactDOM.render is a fundamental method in React used to render an element or component to the virtual DOM. It takes two arguments:

  1. The first argument specifies what needs to be rendered, which can be a React element or component.
  2. The second argument specifies where to render, usually an HTML element in your DOM.

In the example above, we are rendering the App component within the <React.StrictMode> component into the HTML element with the id of 'root'. This means that the entire React application will be rendered within the HTML element with the ID 'root'.

The root element

You may wonder where the #root element is defined. It's typically found inside your public/index.html file, which serves as the entry point for your application. Here's how it's usually structured:

<!DOCTYPE html>

<html lang="en">

  <head>

    <!-- ...other meta tags and styles -->

  </head>

  <body>

    <noscript>You need to enable JavaScript to run this app.</noscript>

    <div id="root"></div>

  </body>

</html>

The <div id="root"></div> element is where your React application will be injected and displayed.

Rendering Elements using ReactDOM.render

While the example provided earlier demonstrates rendering a component, you can also use ReactDOM.render to render simple elements directly. For instance, if you want to render a heading with the text "Hello React!" within the same #root element, you can do it like this:

ReactDOM.render(<h1>Hello React!</h1>, document.getElementById('root'));

This approach can be useful for rendering static content or for scenarios where you don't need a full React component.

Understanding React.StrictMode

Now that we've discussed the basics of rendering elements to the DOM, let's explore the significance of React.StrictMode. React.StrictMode is a helper component that assists developers in identifying potential problems in their React applications.

What Does React.StrictMode Do?

React.StrictMode does not render any visible UI itself; instead, it acts as a wrapper around your components. While it doesn't provide new features for your application, it helps detect and highlight potential issues during development. 

Some of the problems it helps identify include:

  • Components with Unsafe Lifecycles: It warns about components that use legacy lifecycles, which may not be supported in future React versions.
  • Legacy String Ref API Usage: Warns about the use of legacy string ref API, which is discouraged in favor of callback refs.
  • Deprecated findDOMNode Usage: Warns about the deprecated findDOMNode usage, as it can lead to subtle bugs.
  • Detecting Unexpected Side Effects: Helps identify components that cause side effects during rendering, which can lead to issues.
  • Legacy Context API: Detects the usage of the legacy context API, which has been replaced by the new Context API introduced in React 16.

In summary, React.StrictMode acts as a development tool to catch potential problems early and encourages best practices in your React application.


Key: System Configuration, Rendering Elements, ReactDOM.render, React.StrictMode, React Development, React Application, DOM Rendering, Development Best Practices, React Component, React Element, Create React App, Login, Purchased Items, Feedback, Customer Service Portal, React Functionality, User Authentication, Customer Feedback, Development Server, Web Application Deployment, Local Development, ReactJS, Prerequisites

Post a Comment

Feel free to ask your query...
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.