Kashan A.
Technology

React is not a Library, Change My Mind

#react #javascript #web-development #frontend #framework #library

Love the self-definition of React as a “UI Library” when it’s far, far away from being anything that even represents a library.

For starters, I love React and love talking about React, but it bothers me to see bloggers, influencers, and interviewers constantly barging in on the question “Is React a Framework or a Library?” I was on this train as well and asked many, many junior individuals the question, thinking I know very well that I’ve read React is a library, so that should be the answer.

As expected of a saturated job market, most didn’t know anything about the difference between the two, but there was this one talented chap who stepped forward and said “Respectfully, React is a framework, not a library.” I thought I found someone who’s up for a good conversation but he was in for a cup of tea as well.

Here’s the deal, a library, by the books, is a small set of utilities or a utility that you can use to assist your software development processes. You certainly do not base your ENTIRE APPLICATION around this PIECE of software, but only a certain aspect of it. For instance, a small utility that parses timestamps into different date formats for your app can be classified as a library, or simply a utility.

Frameworks, on the other hand, are foundations, whole skeletons on which you build. You DO NOT opt out of a framework once you’ve chosen it and certainly can’t swap it once you’ve built on top of it since your base application depends on it.

Now, those are very concrete definitions, and if you know React, you already know React doesn’t fall into any one of those. For this, let’s choose a bit more abstract definitions to make the world’s best frontend framework, I meant library, fall into at least one category.

Let’s broaden the scope to which a library can be considered a library. Say something that exists throughout your application, say your styling utility, maybe Bootstrap CSS, but you can opt out of it anytime you want. “But Kashan, you can’t opt out of Bootstrap anytime soon. Matter of fact, it’d take you quite a while and a lot of effort to do so.” Hmmm, yeah, and that’s why some utilities aren’t libraries, but something in between.

Now, let’s also broaden the definition of a framework, foundational systems that come with conventions, and a structure that you must follow to make the best of the foundation. Most frameworks, at least on the web, come with routing, testing utilities, CLIs, and all the other magic that you need to build fast and ship fast.

I think we found it, we found the key difference between a framework and a library; being opinionated vs being unopinionated. Is that why React calls itself a library? What does that make Tailwind CSS? What does that make Jest and Cypress? That doesn’t look like a trustworthy defining factor to me. The smallest of libraries can come with opinion and now what, they’re frameworks? The largest of frameworks can come without opinions and now what, they’re libraries?

That brings me to the conclusion of this rant. Don’t trust the Wikipedia definition of everything, use your thoughts and reason with it. The key difference between the two is one serves a small purpose in your app while the other serves as the basis of the app, doesn’t matter how they come, but what purpose they serve. React is a framework, a minimal one, but a framework.

It’s framework enough to demand the whole market to ship abstractions of their libraries specific to it for them to work well. Three.js? Nah, react-three. Bootstrap? Nah, react-bootstrap. The list goes on. React is an ecosystem, not just a framework. Once you React you can’t re-act.

Now, a common argument is that since we use React to build UI components, it’s a library. But those components are not web components, they’re primarily designed only for React applications. Another fairly strong argument is that react is flexible and you can do whatever you want. But you’re still locked into React and can only do whatever React has allowed, you’re essentially still bounded by the boundaries, which exactly aligns with how a framework works.

Now, don’t go ahead saying this in interviews since most folks don’t give it a thought and follow the book, which states React as a UI Library. Saying otherwise would encourage discourse which is not ideal for an interview, lest the organization focuses on growth and critical thinking. I hired the guy who discussed this with me and I got rejected by the guy I discussed it with since he was a steadfast believer in the book.

Back to Blog

Creating web apps the proper way!

I used Astro to put this site together and added a bit of an interstellar vibe. Styling is done with Tailwind, and it's running on Cloudflare. Oh, and all the text is in Bricolage Grotesque font for that extra touch.

Get in touch Open to work