React.js From a Developer’s Point of View – Pros & Cons

Mateusz
Mateusz

React.js seems to be everywhere. Companies, big and small, are using it to develop their applications. According to a 2022 Stack Overflow survey, 42.62% of developers worldwide use the technology. Thanks to Facebook’s use of React to create apps, today, it has one of the largest active user bases in the world.

Developers use React to create interfaces, single-page, mobile, and complex applications.

Although React is so popular, it is generally believed that this cannot be the only criterion for choosing this technology. In this article, I will highlight some essential features of React that are considered its advantages. On the other hand, I will highlight in more detail the situations in which the use of React requires deeper consideration.

So, here we go. 🙂

Advantages of React

Low entry threshold – you can do what you want

If you have experience in JavaScript programming, it’s effortless to start a project in React. It is a library with virtually no architecture and allows you to build what you want in any way you want. Of course, this doesn’t mean that the difficulty level won’t get more complicated over time. To take full advantage of React’s potential, you must have knowledge and experience working with other JavaScript frameworks and tools.

React is often used when building small MVP applications, especially by startups. React developers can write complex code with many features, using TypeScript, etc., but React is primarily used for rapid application development, without a large boilerplate and many complex libraries.

Backward compatibility

According to the Wikipedia definition, “backward compatibility is a feature of a standard, device, or software so that – despite a change in functionality – the new version allows it to work with the entire environment of the earlier version and all its components.”

Included in the React code is the principle of maintaining backward compatibility. It means that the API remains almost the same with subsequent versions of React updates. Making changes is not difficult, thanks to React authors providing step-by-step instructions for migrating an application. Even when the next version comes out, you have time (usually a year or two) to prune elements that are not supported; most often, these include advanced React components.

As a rule, if you stick to the documentation, not much changes in it. For example, when upgrading from React 17 to React 18, the only difference was how to initialize the application, and it takes “a minute” to implement the code changes. It makes it easy to refresh code with older components.

Declarative code

The React.js library has declarative code that describes the end result, but doesn’t say how to do it. It’s akin to visiting a restaurant and ordering a meal. You tell the waiter what you want, but you don’t go to the kitchen to tell the chef how to cook it.

Translating this into programming, you ask yourself WHAT changes you want to see in the interface. You answer by modifying the state of a component.

Reusable components

In React, you can create reusable components or small pieces of user interface and place them anywhere in the application. If you write a component once – for example, “MyAccordion” – the next time you want to use it, you import it and type <MyAccordion /> in the code. Code created in React can be reused, including between different applications. It is effortless to stick to the DRY (Don’t Repeat Yourself) rule, which again results in not having duplicate solutions and is easy to maintain.

Reusable code makes it easy to create and maintain applications. Components can be placed with other elements to build complex applications from simple building blocks. You will create a complex user interface by combining many more minor features. You can divide your website into multiple components that can run independently or update one component without worrying about changes to others. Thanks to its component-complex architecture, React allows you to create a highly scalable SPA (single-page app), where content is dynamically loaded during user interaction.

Virtual DOM

React uses the concept of a virtual DOM model, which is a representation of the browser DOM tree. The idea here is that the “virtual” representation of the user interface is stored in memory and synchronized with the “real” DOM model by the React library.

The virtual DOM works quickly because it only changes individual DOM elements instead of reloading the entire tree each time. It greatly minimizes the need to recreate the DOM for each simple change and massively increases the efficiency of operations.

virtual dom

One-way data flow

The data flow in the React library is unidirectional; this means that data flows in one direction, from the “parent” down to the “children.” This data is called props (from “properties”) and is intended to be read-only.

It looks like the view registers an action that changes the component’s state, such as clicking a button. The state is changed, and only then is the element (“children”) updated based on the state. Child components are not able to affect the parent component. This is a helpful solution when the project has dynamic data and we need to update it frequently. It reduces runtime errors.

react.js data flow

Support of libraries

Due to its popularity, React has created a community providing thousands of extensions called “packages,” downloadable from the repository using the NPM package manager. They allow us to generate HTML files based on code, and some of them will enable us to build React applications rendered by the server. It allows you to customize ready-made solutions for your project without wasting more working hours. It is a huge advantage for teams that need to deliver a production-quality solution in a quick timeframe.

Many popular and proven libraries work well with React. Some examples for UI (user interface) are Material UI and Ant Design; for libraries with tools, React-router, Redux, Styled-components, and React-query; for supporting programmers’ work (linter), Eslint and Prettier. Another useful framework is Next.js, which allows you to create pages rendered in React by the server, making it easier to develop dynamic and SEO-friendly web applications.

The large community of developers

React has many fans, which makes the development process easier and faster. It is practical because when you encounter a bug, you can ask about it in the forums, and there is a high probability that someone has already solved the problem among the millions of React developers.

Thanks to the large community, we also have support from many third-party libraries, tutorials, and React events. Thanks to the fact that Facebook developers develop it, it has good funding, which positively impacts development.

Does React have any disadvantages?

Like any other technology, React also has its drawbacks. Of course, it all depends on the programmer’s level of knowledge and independence. The good news is that React is being refined all the time, and the number of possible problems is decreasing monthly, year by year, and those that do exist are mostly acceptable.

Lack of architecture and standards

React has no architecture, which means no tools for API calls for managing the state of the application; its purpose is to display the page reactively. To take full advantage of React’s potential, you must have knowledge and experience working with other JavaScript frameworks and tools.

Incomplete view

React.js only covers the user interface layers of the application and nothing else. Therefore, when building an application using React, there is a need to include additional libraries to handle other parts of the application. It means that it is entirely your responsibility to find ways to effectively manage several aspects of the application without a predefined structure.

The speed of change in NPM libraries

Although the changes occurring in React itself are not spectacular, external libraries from NPM change quickly, and with the next update, this can be a problem. This, more than once, results in a time suck to create proper documentation.

Plugin authors can make mistakes while developing libraries, translating into possible application problems. To help, developers write instructions as new releases and tools are set in their current projects. The constant changes also make some developers uncomfortable implementing all of them with subsequent updates. Developers must stay abreast of technological knowledge and learn new ways to implement features.

Virtual DOM is not a cure for all ills

A moment ago, I mentioned the advantages of components, but dynamic loading can turn into a trap over time. Can you imagine having to update the DOM for every change caused by user interaction on the page? Fortunately, the virtual DOM means that you don’t have to update the entire DOM tree, just the place where the changes occurred. It works smoothly for smaller applications, but not always. Suppose a developer develops the application’s complexity heavily, adds many components with extensive logic, and does not take care of proper optimization (memoization technique for data, functions, and components). In this case, the virtual DOM can slow down the application.

react.js pros and cons

Summary

Popularity, a large community, many packages, and an entire ecosystem make React a solid and robust framework today. React certainly has its place in the front-end world, but it should be used in projects that fit into it. In the hands of technically experienced professionals, React is a powerful tool for creating reliable, efficient, scalable digital products. 

To sum it up from a developer’s perspective, I wouldn’t say that React is better or worse than any other popular JavaScript framework. The important thing is to match the tool to the problem, not the other way around.

On the other hand, if one were to look at it from a business perspective, I would say that React dominates the market. Mainly because of the large number of developers, many packages are created for many business cases, and applications are developed by the largest community, which makes development easier and faster. 

At Studio Software, React developers have built many exciting projects so far. You can read about them in the portfolio tab. If you would like to learn more about software development, feel free to contact us.