React Javascript Library: Concepts & Tutorials for Getting Started

React Javascript Library: Concepts & Tutorials for Getting Started

React, aka React JS, is a JavaScript library designed for building user interfaces in web applications. It focuses on powering the view layer of the MVC (Model-View-Controller) architectural pattern.

React is based on reusable elements called components that help to create fast and scalable user interfaces—something many developers love.

So, in this article, we will:

Let’s get started!

When to use ReactJS

React is aimed at creating robust and extensible user interfaces (UI) across multiple platforms. One bright spot of React is that it does not limit users to a specific JavaScript framework. React also:

  • Supports integration with preexisting JS frameworks to enhance the user experience of an application—without complex modifications to the backend.
  • Enables developers to easily utilize other frameworks and platforms designed for React, such as Gatsby or js, to power a React Stack.

React is the ideal choice for creating cross-platform, responsive, versatile, and scalable applications when it comes to application development.

Main features of React

To better understand React, we need to know about the components that power it. So, in this section, we’ll go through the core concepts and features of React.

Virtual DOM

The document object model (DOM) is the core part that represents the complete structure of a web page document in any web application. It defines the logical structure of an HTML or XML document and how they are accessed and manipulated, enabling developers to target specific elements and objects with a document directly.

This approach further allows developers to update specific parts of the DOM tree without having to load the complete web page—resulting in:

  • Increased performance
  • A better user experience

React takes this process one step further by utilizing a virtual DOM, which acts as a virtual representation of the DOM tree stored in memory. At the start of the web application, React will create a copy of the DOM tree and store it in memory. React will update the virtual DOM tree when an update happens, then compare the updated virtual DOM tree with the real DOM tree and update only the necessary elements in the real DOM tree.

This reduces overall load times even further and leads to fast, responsive designs.

JSX

JavaScript eXtension (JSX) is a syntax extension for JavaScript. It enables developers to define HTML structure within the JavaScript code. JSX also simplifies the development process by:

  • Increasing the readability of overall code
  • Reducing the need for highly complex DOM structures.

While JSX is not mandatory in React, it is widely adopted because it allows developers to define UI elements with JavaScript. JSX is also used for creating React components.

Example syntax:

Data flow

In React, data is handled according to the “properties flow down, actions flow up” principle. React passes a set of immutable values to the components renderer as properties. The component cannot directly modify these properties, and developers can utilize a call-back function to request modifications.

React state management

All React components have built-in states. This state simply refers to the data structure within the component. State management in React provides a way to both:

  • Create communications (connections)
  • Share data across React components

Every React function or class consists of a state. It’s essential to properly manage the state across the web application as the state of a component can be changed by a user action (user interaction with a UI element).

React offers powerful state management libraries that can be easily integrated into a web application to provide enhanced control over function and class states. Common libraries include:

Routing

One of the crucial parts of a good application is the ability to navigate between pages easily.

Usually, developers will use the History API within a browser to facilitate this navigation (routing). However, the feature set and functionality offered by History API are quickly outmatched when dealing with complex applications.

React provides a feature called React Router in its standard library to facilitate routing functionality. React Router is an API that enables developers to create a routing layer for the application. On top of that, it offers additional features such as:

  • Dynamic route matching
  • Location transition handling
  • Lazy code loading
  • Etc.
Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.