1 post tagged


React is a virus

Early 2012 MVC dominated the world.

In this context thinking outside of MVC box was impossible, and React disguised itself as “V in MVC” (quoted from original landing page). But some people felt it’s not entirely accurate…

“React is the V” just like my iPhone is just a phone. — @_chenglou

Engineers who used React noticed that there’s no place for a Controller in there — React appeared to handle that responsibility quite well.

Then there was the Model. Traditional models were mutable and the View would subscribe to updates to change relevant bits on UI. This pattern was so common that JavaScript almost added Object.observe API. With React, however, this granular model updates wasn’t needed — just re-render the whole UI, it’s fairly cheap.

In fact, mutable models caused a lot of troubles and engineers noticed that using immutable data makes things much simpler and more performant.

Immutable models changed the way the “business logic” was written. It became more natural to write “pure” functions that take immutable data and return immutable data.

Then React started infecting what was known as “separation of concerns” best practice. The prevailing belief was that the presentation should be separated from the data, and it manifested itself in putting HTML, CSS and JS in separate folders.

But to people who wrote React every day it was clear this practice is no good. React components already very elegantly bundle state management and presentation, and having CSS and data fetching in separate places was unnatural. This ignited the boom of CSS-in-JS libraries and declarative data fetching via GraphQL.

And then the virus got to HTML. React could run on the server and render components into a static string, so technically there was no need for HTML shell that used to host it.

React broke free from web with the release of React Native. The component model was so elegant and so powerful that the DOM already an implementation detail. React can now render into mobile primitives, canvas, GL, terminal, etc.

React also changed the way web apps were bundled. In the old days you could get away with simply putting JS files in a folder. React shipped with non-standard JS syntax extension (JSX) and required a small build script that transformed files. It was simple, but it opened the door for more syntax extensions, complex transforms and other sophistication.

React has infected iOS and Android developers, although they are probably never going to admit it. SwiftUI and JetPack Compose build on top of the same programming model.

React has infected me with its ideas. It took over the way I think about building systems. And I’m grateful it did.

4 mon   react