Why React is a Library, and not a framework.

Angie Obiesie
7 min readSep 18, 2023

--

ReactJS
Photo by Rahul Mishra on Unsplash

Since the inception of React, it has expanded at an exponential rate. Its popularity among the most popular JavaScript libraries has grown rapidly, owing to its efficient, flexible, and declarative features, which make it simple to use and allow you to create effective front-end apps with less code and in less time. You’ve undoubtedly seen or used a few React-based apps before. Facebook and Instagram are two examples, noted for their responsiveness and speed. However, as React gains popularity, so does the discussion about whether it is a library or a library (Hahaha!). This article will explain the difference between a library and a framework, as well as why React is a library.

What is React?
React is a free and open-source front-end JavaScript library for creating component-based dynamic user interfaces. It is critical to understand that components and website UIs are not confined to React. The user interface of every website is built on a foundation of components and composability. React is popular in part because it simplifies the process of creating and composing components (for example, complicated state management became something that any React developer could easily do). React accomplishes this quickly and with minimal impact on your browser’s resources.

What is a Library?

Photo by Christin Hume on Unsplash

A library is a pre-written collection of code that simplifies common tasks in software development. Consider it a toolbox full of useful tools, each having a specific purpose. Libraries, like a handyman choosing the correct tool for a job, offer specialized functions that allow you to pick and choose the components you need for your projects. In the case of React, it provides a full set of tools for designing responsive and dynamic user interfaces.

Here are a few examples to help clarify this idea. You have the freedom to select whether to use a package like React Hook Form or Formik to handle forms in your React application and add essential features like validation. However, if your project doesn’t involve many forms, you might not even need a form library at all. Similarly, for handling data fetching, you have choices like the Fetch API or Axios, depending on your familiarity and requirements. Additionally, when it comes to testing your React application, you can make choices like React Testing Library, Jest, or even a combination of both, depending on the specific needs of the app you are building and your proficiency with these tools. Libraries used in software development go beyond React, for instance:

  • Lodash: A JavaScript utility library delivering consistency, modularity, performance, & extras.
  • NumPy: A Python library for numerical computing that provides support for arrays and matrices, along with mathematical functions.
  • Pandas: Another Python library for data manipulation and analysis, particularly useful for handling structured data like CSV files and databases.

What is a Framework?

Photo by geraldo stanislas on Unsplash

A framework, on the other hand, is a more comprehensive and opinionated tool. In contrast to libraries (flexible/unopinionated), which offer fewer predefined rules and give you more freedom to choose how to structure your code and build your applications, frameworks have strong and predefined structures, architectures, and workflows, which means that developers using them are guided towards a specific approach to building applications. Frameworks impose particular architectural principles and design patterns, creating a solid basis upon which you build applications. They regulate the flow of your application and typically require you to adhere to a predefined structure. Frameworks often cover a wider range of application development aspects, such as data management, routing, and user interfaces. For instance, Ruby on Rails covers everything, including how data is stored and how web pages are displayed. However, the degree of built-in functionality can differ amongst frameworks; some, like Express.js, offer a more basic foundation and leave it to third-party packages and middleware to implement key features, such authentication and validation. Here are some more instances:

  • Django: A a high-level Python web framework that encourages rapid development and clean, pragmatic design.
  • Angular: A free and open-source single-page web application framework.
  • Express.js: A back end web application framework for building RESTful APIs with Node.js
  • Laravel: A free and open-source PHP web framework
  • Spring Boot: An open source Java-based framework

The choice of framework often depends on the specific requirements of your project and the programming language you are most comfortable with.

Why is React a Library?

One of the important distinctions between libraries like React and frameworks like Ember.js and AngularJS is that React is concerned only with rendering the UI and leaves many things up to each project to put together. While React equips you with tools and utilities for crafting interactive web applications, it does not impose an exhaustive application structure like frameworks do. The distinctive feature lies in its flexibility and adaptability, allowing you to seamlessly integrate it into projects. This unique trait positions it as an ideal choice for crafting user interfaces, offering the freedom to leverage other libraries and tools for additional functionalities.
Even with the provision of the create-react-app (CRA) setup, React still retains its classification as a library. This flexibility not only empowers you while you work with the library but also extends to React-based frameworks, enabling the creation of robust, feature-rich applications while simplifying the decision-making process throughout development.

React-based frameworks:

These frameworks offer the advantage of speeding up project development without being overly dependent on several third-party libraries. Next.js, a framework that is becoming increasingly popular and in demand, is a good example. With its strong support for both front-end and server-side rendering (SSR), Next.js stands out as one of the most well-known React-based frameworks. It is the best option for building full-stack applications that take advantage of SSR because it excels at managing server-side rendering of React components with ease. React-based frameworks differ in their intended uses and capabilities, similar to Express.js among more opinionated frameworks. It’s crucial to remember that not every React-based framework is made to accommodate needs for both client-side and server-side rendering. Allow me to clarify: Here’s a clarification:

  • Next.js: This is a React-based framework that is designed for both front-end and server-side rendering. It allows you to build full-stack applications, rendering React components on the server side for improved performance and SEO, in addition to the traditional client-side rendering.
  • React Native: React Native, on the other hand, is primarily used for building mobile applications for iOS and Android. It does not handle server-side rendering like Next.js.
  • RedwoodJS: This is a full-stack serverless web application framework based on React and GraphQL. It’s designed for building web applications but may not specifically focus on server-side rendering as its primary feature.
  • Gatsby: Gatsby is a static site generator that uses React for building static websites. It pre-builds pages at build time and does not typically handle server-side rendering for dynamic data.

These React-based frameworks streamline the creation of dynamic and static React applications, offering a significant advantage by reducing the number of choices developers must make throughout the development process while still enabling the creation of equally functional and feature-rich applications.

Benefits of Libraries:

  • Libraries give you freedom in component selection, allowing you to use only what you require or even combine several tools and components as necessary for your project.
  • They may be quickly incorporated into current projects, cutting down on development time without necessitating a whole rewrite of your programme.
  • Libraries often have a lower learning curve than frameworks, making them more accessible to a wider range of developers.
  • By offering tools and components that are optimised for a given activity, libraries speed up development process, saving time and effort.

Limitations of Libraries:

  • The use of libraries frequently necessitates the difficult and time-consuming integration of several components.
  • Because libraries are specialised, you might need to use different tools or create your own code to complete tasks that are outside of their scope.
  • Larger projects may lack uniformity and consistency in their organisation and design without the established structure offered by a framework since libraries provide less guidance on how to build your programme, which may result in inconsistencies in bigger projects.

Benefits of Frameworks:

  • Frameworks ensure that project structure and development practices are consistent across diverse projects by enforcing conventions and coding standards.
  • They offer a thorough framework and predetermined design patterns.
  • Frameworks frequently provide a robust ecosystem of community resources, plugins, and extensions that promote interaction and increase functionality.
  • They speed up development by providing pre-built tools and tried-and-true processes, eliminating the need to start from scratch.

Limitations of Frameworks:

  • Due to their comprehensiveness, frameworks may have a higher learning curve and necessitate adherence to particular guidelines.
  • Your flexibility in selecting components and architecture may be hampered by frameworks.

Having gone through what a library is and how React checked the boxes, you’d agree with me that React is a strong library for developing user interfaces, not a framework. The differences between libraries and frameworks can be subtle at times, but it is critical to correctly classify them based on their roles and features. Understanding these differences is critical for choosing the appropriate tools for your development projects. While libraries such as React give flexibility and simplicity of integration, frameworks provide a structured foundation for more extensive applications. Recognising React’s function as a library allows you to make informed choices and efficiently harness its features in web development.

--

--

Angie Obiesie

Software Eng. | Developer Relations Eng. | Technical Product Mgr. #Business💼 #Tech🧑‍💻 #GoodLaughs😅