by cageface · 10y ago · 0 comments
And yes, React is as much a technique for building UI as it is a particular implementation. Learning and using React has also improved the iOS code I write.
I use it at work on a page-by-page basis-- it drastically reduces the mental overhead of class naming, JQuery spaghetti, maintaining the DOM etc. Sometimes I even surprise myself when something "just works" because of React's well-controlled model.
This is Reacts greatest strength and a huge design constraint they had from day one. On the other hand it's a tradeoff and as everyone mentioned not having the whole stack under "one roof" brings a lot of tedious crap.
If you need something to incrementally rewrite parts of your frontend React would probably the best choice. If you need something to start your project on I'd consider other options, Angular 2 and Aurelia for example.
Back in the day, jQuery was amazing because it made selecting and manipulating DOM elements easy. But now, plain JS has mostly caught up to that functionality, to the point that it rarely makes sense to use jQuery over plain JS. I wonder if in a few years the same will be true of much of the functionality in react.
Before with libraries like jQuery every potential action had to perform it's own UI modifications.
As the projects grows you have the same UI element being controlled from many different sections of code. States and state transitions not clearly defined.
With React you set the state and the UI will always match, no matter how the current state was achieved.
The purpose was to get rid of ad-hoc DOM manipulations.
The Flux architecture just takes this a bit further by formally defining who holds onto the state/how it's accessed (stores) and the availible possible state changes (actions).
jQuery was all about selecting a node or node list and then applying manipulations to it.
We're moving closer to having real GUIs in the browser (e.g., Java Swing) but that's not a function of the language, but the plumbing around the language. Swing isn't Java, Swing is written in Java.
But again, JS is just a language, that happens to have an interface into a DOM (in some environments). It's not a framework that guides you in how to organize and architect an app.
It's possible to write maintainable, high-performance, complex apps using plain JS. Adding a few simple layers makes it a lot easier, though, and I'd argue that the current crop of client-side frameworks make it easier still. Simple apps == simple code. Complex apps == complex code, regardless of the tools used to create it. Underneath everything, after all, is still just plain JS.
Redux is very core concept. You'll have to rewrite half of an application, unless you use it from the start. Routing is essential for any serious web site, so you have to implement it one way or another, and not using working libraries looks strange. Same about babel — either use it from the start or rewrite half of code later (or have a mess). Also I think that babel currently the way to process JSX, so unless you avoiding JSX (which would be very strange), you have to use it anyway.
I don't agree, that you can avoid all this stuff, unless you are just learning on throwaway pet projects or willing to reimplement a lot of things which are already have good enough implementation.
A full frontend stack is total overkill for the vast majority of projects that fall under the "open, check, close" use case. So many of the perks of those frontend stacks, such as keeping data in the browser and only reloading certain parts are based on the slow load times of a full frontend stack if you don't do all of those things.
Being able to use pure React both client and server side without anything else is a fairly significant perk.
Redux is something you can implement yourself easily, I never understood the need for a library there.
The good idea of redux is to have a serialisable state which is changed through events. This gives you unidirectional data-flow and the ability to pause/restore your application.
Complete immutability and funneling everything through functions on the other hand often just obscures readability, and, in case you are using immutablejs, gives you terrible performance.
If I want to have purely functional programs I don't use Javascript, but Haskell or something. If I need time-travelling debugging, which I never found very useful when dealing with complex states, I'll implement it by copying my state using serialization.