Re-rethinking best practices with React, ft react-suspense
In recent times we are seeing a big shift in the way we do front end thanks to React community i.e. MVC is not the norm, we don’t write CSS in CSS, we don’t write HTML in HTML, we don’t necessarily do templating and now we are going to start throwing promises (not actual promise but you know JS promises). I am going to talk about why certain pre conceived notions of best practices can be broken by setting some simple constrains on the mental model/systems and breaking those notions can actually result in some cool breakthroughs and features.
I will be going through different established best practices and constrast it with how React approached it to show why its sometimes okay to break it, if it results in some awesome possibilites.
For example, MVC was the norm and most frameworks tried to adapt to the pattern which resulted in too much context switching while managing controllers/models/templates and keeping them in sync resulting in loss of productivity, increase in complexity and just by taking a component approach where all of that is encapsulated using pure functions and immutable state we are better able to reason/compose our UI and considerably more productive.
Finally I would like to talk about react-suspense. A new feature thats going to get introduced where they have used something like try/catch as means to control side effects which is unheard of and in doing it they have made the render function a “impure” function yet it results in clean abstraction. Again they took a really unconventional way which resulted in good abstraction and some cool possibilites.
I am a consultant with Equal Experts and have been building UIs for a couple of years now.
When I started doing front end programming I learned bunch of stuff from various sources to be best practices and coded as such, in doing so I could see the problems with it but since all the sources I had told me that it was best practice I assumed there must be some wisdom in it that I didn’t see, so continued to code as such. Only after React came along I felt like finally somebody agreeing with me :-).
Of course that doesn’t mean that all best practices are bad practices just that sometimes we stop questioning things just because its the norm which stopped me personally from exploring new stuff, so I want to share that wisdom and the insights I got along the way.