Is React A Framework
20 Mar 2024 - Ben
Or is React still a library? React started as a library to enhance a webpage from server rendered templates, like Rails, Laravel, or Phoenix. Sprinkle a little extra interactivity on and you can enable much more than the browser on its own. Did this ever mean you were mounting React in multiple places on the page? I wasn’t there for it, so I don’t know. I’ve never seen a website like that, but it would fit with progressive enhancement and the ethos of React being a library.
Now, React has a framework and a majority of apps send only enough html over the wire to mount their React app (if any, some apps bootstrap through javascript too!). With React Server Components (RSC) and Server Side Rendering (SSR), what’s different with React than server rendered templates a couple of decades ago? They’ve been making improvements too!
React as a templating language can be much more expressive than things like Handlebars. But erb and heex also fully embed the language, so Javascript is then the choice language, not the only language.
Then there’s the argument for one language for front and back end, like JAMStack has always evangelized. But most React apps seem to still only be the frontend, communicating wiht a backend that could be in any number of languages. If it’s doing this, now you need to have 2 deployments, typically 2 repos, etc.
If your Next.js project is your entire app, you might still argue for the better interactivity it provides; since with RSCs it provides server actions and streaming. But they aren’t the only game in town; LiveView takes this up another notch by providing stateful sessions. Hotwire enables full control communicating back and forth in a language agnostic way through a few html-compliant web components, and even dips strongly into native apps.
If React were still a library, it should be competing with the likes of Stimulus not the likes of Rails. If it is a framework, running as much on a server as in a broswer, then it’s not as batteries included as Rails, nor does it have as refined an ecosystem as Laravel. It feels like React is straddling two worlds today, but I’m not sure it’s doing either well anymore.