Did React become a framework?

Posted December 23, 2021 | Updated January 3, 2022

React has been focusing more and more on server-related features prompting the familiar question: Is React a framework or a library?

Spoiler alert: Both. It was always both.


If you're unfamiliar with how we got here, one of the appealing features of React near its inception was: “it’s just a library”.

This was in opposition to other similar frontend tools that grew popular at the same time as React. The typical form of this would be:

  • Angular – the framework vs
  • React – the library

And most resources I've seen would suggest React as the "winner" here due to its simplicity and focus in contrast to the complexity and scope of "big frameworks" like Angular but there’s more to the story.

What's different now? Why is React no longer "just a library"?

People say React is no longer just a library because the React team is now implementing features that require more coordination between client and server.

Under certain technicalities, this breaks the boundaries of "just a library", however this isn't as notable as it seems.

Challenge: Was React was ever just a library?

A JavaScript library is something you install, import, and call yourself. There's a level of self-containment and isolation expected in libraries that distinguish them from frameworks.

If you look at a more formal definition:

  • a library is a piece of installed code you call in order to use it. You have code that wraps around it and you control when it's invoked.
  • a framework is a piece of installed code that calls you. You configure it and provide it with pieces of runnable code and you give them larger control when your code is run. They’re also typically extendable and pluggable.

Disclaimer: don't get too caught up on these definitions. They're more or less academic formalities and people tend to mean different things when using these words anyway.

Under this definition, was React ever just a library?

Let's take a look at some legacy React code that used React.createClass.

var MyComponent = React.createClass({
  getInitialState: function() {
    return {count: 0};
  },

  handleClick: function() {
    this.setState({count: this.state.count + 1});
  },

  render(): function() {
    return (
      <button onClick={this.handleClick}>
        clicks {this.state.count}
      </button>
    );
  }
});

ReactDOM.render(
  MyComponent,
  document.querySelector('#app'),
);

This code is of a button that keeps track of how often it was clicked. We give some code to React and React calls us.

And once you start building larger apps, it becomes clear that React isn’t a library like jQuery is library. You end up relying on so many React lifecycle methods (e.g. componentDidUpdate) and hooks to compose, extend, and customize the behavior of React that it’s hard to say that it’s not a framework in this sense.

Challenge: Is React still just a library?

On the flip side, when you compared to Angular, React really does seem more like an unopinionated library rather than a framework.

Why? Because Angular provides first-party solutions to things that React does not. For example, Angular has examples on their site for routing and navigation, forms, and data fetching.

React does not. As a React developer, you're expected to choose your own set of tools to create your own "framework".

In this context:

  • a library is an unopinionated tool that often calls for it to be paired with other libraries to create a framework
  • a framework is then a complete solution to problem.

React has fallen and still falls under the category of library here. This is by design.

It's unopinionated, meaning it doesn't provide a first-party solution to every problem. This is so that the best community tools can rise to the top and change over time.

So what is React then?

As I was alluding to above, the library vs framework debate isn't very helpful at explaining what React is so let’s do that now.

React is a paradigm

Stated by the React team themselves:

React is more than a library.

React is paradigm for building user interfaces.

[source]

And marketing aside, I do believe this to be nice a explanation of what React is.

After you've learned it, it starts to manifest itself as more than a library but something different than a framework.

It's its own sub-language (especially when considering the rules of hooks), it's a set of conventions and best practices, and after a while it really does become a way of thinking.

However, this also means that it takes a significant time investment in order to fully utilize it and speak it (which is not in the spirit of just-a-library) and some specific skills you learn in React are only applicable to React.

React is an open platform

Additionally, React acts as a platform as in something you build on top of.

React was, and still is, designed to be (mostly) unopinionated. Even now with React creating more opinionated patterns of doing things (like fetching data), they’re not locking you in to an implementation. React is pluggable and many React library devs are already prepping for new React additions.

This is why the React Working Group exists—to work directly with the community to provide more than one choice and gather feedback to ensure React works for everyone.

Some final takeaways

  • React is still a library in the way you can import it and call inside of your different projects to create UIs.
  • React is (and always was) a framework but also a bit more. It's a paradigm for creating UIs, which does mean it takes a bit of effort to learn and "speak" React but once you get there, it can be used for multiple platforms (React Native, VR, etc).
  • React is open. With the creation of the React Working Group, React works directly with the community to improve APIs and fit everyone's use case.

Bonus: How should you answer "What is React"?

You can still say it's a library for creating user interfaces.

…or you could call it a framework, or a paradigm, or even a UI Runtime. They're all correct.