by _prototype_ · 6y ago · 0 comments
It actively encourages mutability, which is a one way avenue to bugs bugs and more bugs. ie, shit like this is all over the official documentation:
<script>
let mutable = 1;
function f1() {
onMount(() => {
mutable = /* do some complex shit here */
});
}
function f2() {
onMount(() => {
mutable = /* do some complex shit here */
});
}
</script>
<Component onclick={f1}>
<Component2 onclick={f2}>
</Component2>
</Component>
Complete non-deterministic state changes. Absolutely abhorrent stuff. Cannot believe my coworkers and others actually like using this absolute garbage of a framework.If you wouldn't mind reviewing https://news.ycombinator.com/newsguidelines.html and taking the spirit of this site more to heart, we'd be grateful. The idea is curious conversation, and you'll be better able to persuade others about mutability that way anyhow.
Not sure if all this immutability talk in the JS community is parroting because "it's what Facebooks does" or what. Maybe it makes sense once you are building really big front end projects but personally I've never had an issue with mutable state in small to medium sized projects (less than 50k LOCs). Although I admit I've never worked on a Facebook-scale kind of project.
I was thinking the same thing at first, why have this monstrous global state which is against every good practice you have ever heard of.
But then, if you want to keep state when switching between pages, you need to hoist up that state to the parent component. At some point, there's going to be a component near the root that keeps a lot of state for its children, that then has to be trickled down the component tree.
If you don't need to reuse those components in a different setting, then the redux solution feels quite ergonomic.
Now, this is coming from an embedded C programmer point of view, and this is my first foray into react/redux, so I'm obviously lacking context. But we're writing a front end for our embedded device, and I have to say I am pleasantly surprised with the experience.
You might want to watch my talk on "The State of Redux" from Reactathon 2019, where I covered some of this:
https://blog.isquaredsoftware.com/2019/03/presentation-state...
Also, note that we have a new Redux Toolkit package, which is intended to simplify many common Redux use cases, and is now our recommended approach for writing Redux logic: