28 points · by kirso · 4y ago · 53 comments
I am a hobbyist. I don't intend to take a career in front-end (maybe in a decade) and just hacking away on my own small projects using external APIs. It is probably for another post but after being scared of coding for such a long time, it seems so interesting and kind of a new world (despite the frustrations obviously).
The thing is, I came quite late to it and learned the basics of HTML, CSS, JS whilst finally delving into React which has been... welll confusing. It generally feels like an overkill and learning new things about it not enjoyable anymore as a beginner.
I have delved into Svelte in the past week and it just has been a completely different story. I am not associated with them, and I am not trying to promote it as I want to just ask whether React felt as frustrating as for me or am I missing something?
I suggest you look at these frameworks:
* Vue: Personally have never used it but from everything I heard, it's much easier and more straightforward than React.
* Svelte: I've used this framework and it's amazing. Intuitive and very fast. Some things are specific to svelte and sveltekit but for the most part you are writing plain HTML, CSS and JS code.
* SolidJS: Also have never used this but heard good things about it. It uses JSX tags just like react does but it's far far simpler.
There's also Preact but it's main selling point is to be a "lighter" React, so expect similar complexity here.
The change is essentially a clone of reacts “hook” API, it’s called Composition API and it also makes reactivity now much more verbose again with no real explanations why it must be so.
I still consider the way most people using Vue to be the most productive - the retroactively named Options API where you have a simple object defining a component.
Initially it was advertised as “this should only be for advanced components perhaps the sort you’d find in a component library” but now it is “use it for everything lol”.
It is a shame that one of the things that appealed to developers and lead to its wide spread adoption due to its low friction approach is now so often overlooked or ignored because internally there’s a desire to have feature parity with React and all the downsides of that.
I also don’t believe the Typescript argument where they claim composition API has better support, with Vue 3, TS, and Options API I’ve yet to find any downsides.
These changes are troubling enough, but when you add in the constant build tooling churn (eg instead of making a breaking change to Vue CLI they’d rather suggest people use a whole different tool, while still maintaining both) or the fact that the Vue component testing library has some serious conflict of interest with Cypress the organisation that I believe has lead to poor judgment and deprecation of certain aspects of the unit testing library…
It certainly has been disappointing to see this happening. It makes me worried about the future of Vue with this deliberate fragmentation.
Like I said elsewhere, React is a set of extremely simple, foundational building blocks that groups of extremely smart people have thought very long and hard about. Vue is, IMO, like someone's knee-jerk reaction to not understanding React and deciding they would build their own framework that does things in ways they think make sense.
The result is just more redundant complexity, worse tooling and a horrible, dead ecosystem with awful libraries or components that are barely even usable.
And by people I mean the actual developers using it in production, not the dozens of charlatans hyping the latest change or addition with millions of demonstrations at the latest conference of how composition api hello world is somehow better than what already exists.
Alienating the actual fans and users alike is a poor strategy.
——
As for the build tooling and dead ecosystem and poor components yes I absolutely agree, it’s a bit of a dumpster fire. There’s certainly good libraries and components but in comparison it’s miles away from react.
One of the things I strongly dislike about Vue is the fact it’s prototype is just freely floating around everywhere and all the plugins just attach garbage to it and then get users to do the same.
A strong lack of software engineering practices and competence means that on average many Vue libraries are absolutely horrible to use with equally awful code. In many cases it’s been better so simply have a quick scan of what a library or component is doing and then write a better version yourself - this time with actual unit tests and linted code.
For example, find some library that does something fancy with the DOM like a tooltip or some animation or some wrapper for a popular library.
The process is like this:
> Google for it and find 1 or 2 results
> One was last updated in 2017 and has “Vue2” in the package name (poor)
> the other mostly works and has a few hundred GitHub stars simply because it’s the only one
> use it and find some edge case that makes it useless
> also discover it doesn’t use slots (the actual way to do “composition”, much like reacts child render props to allow components to be inside others) meaning it’s now fully useless for your use case
> write your own version, based roughly on the code in the library - and read the unit tests to make sure you account for anything else you might not have thought about (if it even had any tests, most don’t because it was written by someone that barely knew what they was doing or is the kind of person who hates testing (because then they don’t have to be accountable) you have to argue with over the value of unit tests)
> job done, many days or weeks later
This poor ecosystem seems to go hand in hand with a vocal minority of Vue users that seem hopeless at trying to debug any of their issues or self inflicted bugs.
Preact is actually a good alternative not just for its size/perf advantages. It’s also significantly easier to read and understand the internals, which may help some learners find their way where they would otherwise get lost in React.
It’s also extremely opinionated and generally taking a backseat to tools like Next.js if your team wants an opinionated starting point.
If deadlifting is stopping you from going to the gym then go to the gym and just don’t deadlift.
But “React” community practices include approaches that you may find anywhere on why..yagni..cargocult..bizarre spectrum. Even it’s own state management routines require you to think orthogonally to everything you know and used before. So as a rendering engine it’s okay, and maybe the best due to its widespread nature, but I wouldn’t go any deeper than that.
On the pro side, React isn’t tightly coupled to its state, so you can connect your own state to its rendering cycle. If your hobby is making products, not frameworks or meta-things, it has no value for you in my opinion. Stick with svelte, vue or lesser frameworks like mithril, whichever fits your needs better.
This opinion comes from a guy who avoided web ui like hell, but had to take a dive 3 years ago. Since then I used vue, mithril, react, researched multiple lesser/toy frameworks. Before that I was using Gtk/Gdk, Qt, Wx, AppKit, UIKit at work, and was toying with many desktop/mobile ui frameworks including the ones created by myself. Frankly, React feels like a pile of… idk it’s not even BS, something completely out of this world. As if someone learned nothing but js and html, read about FP and made first insecure steps into this journey.
I don't think you understand what React does
I’m afraid that anything I say here would lead you to think that I was jQuery, but no, I never wrote a line in it. I had these conversations before, so please excuse me for this digression. I know how React works, and I could build it myself, barring some optimizations. You are right, I don’t “get it”, but not in a sense of how it works, but why it does that. It solves the issue that exists in jQuery and other call-manual-update approaches, but that is not an issue in what I worked. It reinvents a wheel that was already there when it was born. I spent enough time with it and its community to check these ideas.
I’d like to hear what you have to say though. Maybe there is something I missed.
What do you mean by this? I've really only used React in my career so I don't have a frame of reference. Are you just talking about having to keep immutable state?
The upside is the components are so compose-able once you have them (buttons, forms etc) it's easy to build apps. Also the fundamental idea, UI as a function of state, makes the app much simpler, because invalid states are harder to reach (generally presuming typescript).
The downside is it is quite large time investment to become proficient. The 'UI as a function of state' idea makes some simple things (anything with side effects) awkward, because the raw idiom doesn't allow for it. There are also rabbit holes of complexity you can easily get stuck in, like redux or integrating rxjs, because the simpler ways aren't always obvious.
I feel like the function of state stuff is the tacit knowledge part that is actually most important but I'm kinda skipping it. The bit I like the most is the lego bricks. Building web apps with component libraries and not having to think at all about HTML or CSS if I lower my standards a bit.
Even from tutorial perspective, people tend to explain react like here is useState and if you do this, you can now update other parts. But I am a newbie so I guess its either sucking up and spending more time with it or just struggling with trying to solve the same things with more code in vanilla ¯\_(ツ)_/¯
All of the external tooling required is a huge turnoff… I wish it weren’t necessary. If I could just fire up a browser and plain text editor and start writing a reactive web app with zero dependencies like I do for plain HTML/CSS/JS sites that would be like a dream.
If you have very little experience and have only built simple things, the disadvantages of building a web application using traditional imperative DOM manipulation won't be clear to you. But as soon as you start building something complicated, these disadvantages start to show themselves pretty fast.
Imagine that your application is complicated and needs data from many different API calls and has a lot of state which can cause it to do different things at different times. With simple DOM manipulation, you will end up with a codebase where nearly any part of it can be doing modifications to the DOM, regardless of what else is happening, and you will probably spend quite a bit of time fixing bugs from, say, two async functions running at different times and thus resulting in a broken DOM or something.
To remedy this, you take a step back and you figure that you should probably build an abstraction which takes care of this. You do things in stages: 1. Do all async work 2. process data 3. render UI from data. Now things are certainly a bit simpler and you've avoided the DOM race conditions, but you're running into performance issues, because you're re-rendering your entire application from scratch every time you get new data.
You can optimize this on a case-by-case basis and try to ensure that some of it can happen in parallel, but to do it generically, you essentially have to do reconciliation.. and at this point, you're already halfway to writing something like react/angular/vue, just minus the millions of manhours that have gone into those frameworks to make them work as well and as efficiently as they do.
I think that you should do whatever you feel like doing because that will give you the best experience. But I think picking up something like React will definitely benefit you in the long run, and if you ever decide to try to do this professionally, it is pretty unlikely you'll find a place that builds serious web apps using vanilla JS / CSS / HTML(and even if you did, you probably don't want to work there).
Thank you for the great examples on complexity though - was really helfpul to understand.
To be honest, I think it’s best to learn React without hooks first. Hooks are very confusing from the start, with far too many rules and too much ceremony for an API that looks simple. Without hooks:
- Most components are pure functions of props, which is why React was appealing in the first place
- You can manage state however you like, again React’s original value proposition
- You’re encouraged to actually isolate those cases! This is woefully uncommon in many React codebases.
On the isolation part, I feel like if Hooks were taught in a bit of a different way particularly with the isolation example, it would probably be less scary. I learned something new today :)
- Hook rules in general
- Hook semantics for basically everything except useState
- Suspense
- Portals
- Server Components (I know it’s still considered “experimental”, but it’s already in use by large projects/meta-frameworks)
- Even the “new JSX transform” has a couple footguns
Of course you don’t have to use any of those, but for most real world front end projects that would likely mean reaching for ecosystem tools which, as you said, come with their own complexity and choice on a paralyzing scale.
React requires a very particular mental model. You define a state for your app and your view is a function of that state. Most of nuance of writing react has to do with deciding where state belongs and how to model it. This is very powerful.
I believe it is worth learning React to grok this model alone, and you can absolutely apply it to other frameworks and even other aspects of building apps.
Yeah you are allowed to do that if you are a hobbyist, or if you are like me and a solo developer of a product. We are allowed because no one can stop us.
Component frameworks are useful though, and it is likely that if you bring in another developer to your project at a later date they will want to do it over in React or whatever flavor-of-the-month they like.
In my opinion, if this happens it's okay, because by that time there will be new frameworks and web languages that are popular (e.g., suddenly next year all the cool kids build websites in Ocaml, Dream 3.0 and web assembly) and the old framework you used won't even necessary be relevant anymore. Also no one really wants to pick up another person's large codebase anyway. They will be happy to do it over their own way.
React is designed for businesses to work on large applications. It can be nice to use if you know it well enough, but you certainly don't need it.
There is nothing you can do with React that you can't do with other frameworks, or even in vanilla js. It can make certain things easier, like testing UI components due to its functional design (ie, a component will always be exactly the same given the same input), and going back and forward through time is harder to do without React-adjacent libraries like redux.
Don't worry about it. Sometimes vanilla js or other frameworks are honestly just faster or better suited, especially if you work alone.
That's why I say: stick to the baseline of HTML, CSS, & JS. Learn to write vanilla JS for common things, maybe learn UmbrellaJS[0] for syntactic sugar and manipulating the DOM.
Oh and learn some APIs to do back-end stuff too. And for forms, there's loads of projects out there to automate that[1]
Svelte is just perfect for small to medium projects. I’ve never used Svelte in a professional team environment though. And that’s where React is best- enterprise environment with a team.
For hobby; svelte 100% Less boilerplate, super easy set up and you write less code in general.
That being said, it's probably much easier to learn and more fun to use some of the alternatives.
(I spend all day in react and like it, but understand people’s reactions.)
React is basically: JSX, useEffect, useState(plus a couple more) and reconciliation. React is the result of a group of very talented people spending a lot of time thinking about what the core of a framework like this should be. There is a very good reason react doesn't have more bells and whistles, because it's basically at a local minimum(in terms of complexity). What we have are tiny, simple foundational building blocks from which we can build larger and more complicated abstractions. There is nothing else in this space that is as simple: Angular and Vue are both basically "react with more bells and whistles", and sveltejs requires an entire compiler and has its own share of problems.
To save you an hour or so of reading its guide, the only key difference between Mithril and React is how VDOM updates are handled. Mithril always renders the entire “v-screen” on any vnode-related event out of an assumption that it changed something and DOM shouldn’t be too large in its div size. You can take it down with e.g. heavy svgs, but that is also true for vue, react, whatever. No framework can compare tens of thousands of vdoms efficiently, it’s always >= O(n). These cases are handled by mounting sub-apps at these points, so that redraws don’t descend and events don’t bubble up. React also advises against that and suggests “windowing”, also a very fresh and interesting approach (for those of course who still aren’t aware that it’s called a scroll view controller and is the core of all desktop ui frameworks since circa 1990).
React is easily the simpler of the two, and Vue is the one that forces you to do things "its way" a lot more than React does.
If you're referring to being able to, say, interact with state by just mutating it.. well, that's because Vue has a built in reactive state system that works similar to Mobx.
In react, you can just use Mobx.. or recoil, or redux, or even your own custom state management system if you really wanted to(as long as it talks to react properly).. In vue? Maybe, sort of, but you've already bought into one heavy-handed abstraction which is their own reactive stack, so the best you can do is build on top of that.
Only after you get frustrated by adhoc nature of all the frameworks that rely on arbitrarily hacking html syntax and get lost in tangle of event listeners, triggering who knows what and when and in what order and state distributed over various html tags you might come to appreciate react revolutionary model and its exceptional consistency and composability.
As a hobbyist, if you’re getting what you want out of vanilla JS, stick with that.
There’s no reason to chase all the frameworks if you’re already accomplishing what you want.