Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Voxera115851yThe syntax is to ensure good state management, bad sate is the most common problem with vanilla js pr jquery and react is designed to try to enforce consistent state.
If you do not understand why its as it is, chances are you also do not really get the benefits with react since it sounds your fighting the framework instead of embracing it.
And if that is the case you probably should not use react, it might not suit your preferences. -
"Notice that again, we are destructuring the returned values from useState.
The first value, color, is our current state.
The second value, setColor, is the function that is used to update our state."
https://w3schools.com/react/...
So it is destructuring like in Python / PHPs each / ...
Two variables, one representing the value, other the callable / function.
Is that what bothers you? The destructuring? -
I guess it's about this seemingly atavistic need some devs have to shoehorn their framework into *everything*.
I remember in my old company, I needed a task done. Taking UE4's web build artifact (a .js), and modifying a function so it could accept load requests from urls in addition to local packs.
All it took was 5 lines and could be done in 30 mins.
Fucker just *had* to fucking add Vue to the whole thing because it seems like "hurr durr no freemwork no brain". -
jassole18401y@Areg damn, my feelings are hurt!!!
How dare you insult my favourite framework React?
But seriously, post how would you design it? You are sounding like a noob trying to be a smartass. -
Areg811y@jassole Anything but deconstructing it, why not have like a global function to set the state? like setState({yourshithere}) and then access it using this.state.myshit? or even better why not create a file that will include everything that should be set up in a state file? instead of cluttering it all over in the files.
-
jassole18401y@Areg If you are talking about a global state, you can already do that using the context api.
https://react.dev/learn/...
But afaik all major frameworks start out with local state.
React with classes used to have `setState` but in general hooks provide more reusability. That said, I don't prefer react in general myself. -
@Areg
In which moment did it seem to you I was hurt because anyone criticised my favourite framework?
It's clear from my post that my favourite framework is none. And people shoehorning them in the simplest of situations really grinds my gears. -
@Areg because it would be an anti pattern...
You have a component. A component is an independent and reusable part of the whole react app.
A global state, as in a state shared between components, should be avoided.
Is possible with context if I remember correctly, but ... Unless it's necessary, don't do it. Keep the components independent, as that makes it far easier to maintain / extend and reuse them.
A component itself doesn't need to have a single state.
It can have multiple states.
Destructuring is actually a nice pattern - common in many languages - to reduce boilerplate code.
It also prevents funkyness regarding JavaScripts object handling.
const object is not the same as const { value1, value2 }.
const is a VERY misnomed thing in Javascript...
An object in const isn't immutable.
https://developer.mozilla.org/en-US... -
Areg811y@IntrusionCM i totally understand, but why would i ever need to deconstruct it? Why should i always have the option to "name" my own setter and getter? its absolutely stupid
-
@Areg
You *can* set your own names when destructuring, by using the
let {prop: newname, prop2: anothername} = someobject; -
Voxera115851y@Areg You do not “need” to deconstruct it but since useState returns an array with two objects, using the array to get the state and to update will make the code less readable.
Yes, they could have returned an object with and value prop and an update method but that would also in many cases lead to more cluttered code.
In the end its just a design choice they made and one that most users of the framework likes or accepts.
Just like the = for assignment and ==/=== for comparison instead of := for assignment and = for comparison.
Destructuring is as mentioned a common pattern that is used quite extensively and they are using it consistently which is good. -
jassole18401ySo far I've only heard noobish suggestions on how to rearchitect it. Which is just complains about minor syntactic change and remaining be solved using 1 - 2 most popular state management libraries ....
NOOOB PUBERTY BOY WHO PRECUMS seeing react CONFIRMED!!!!! -
Good read, to whom it matters react is not a framework but view rendering library. It has grown and changed a lot overtime. If you dont like hooks, I believe class components are still available, just not widely used. Im fairly sure after understanding shortcomings of class components hooks will start making more sense. If not liking react there is plenty of alternatives especially when not interested in setting up plumbing. Maybe go for something else?
-
Voxera115851y@Areg then you should not use react, they have made their decisions and react have grown to be one of the most used libraries so obviously not everyone share your opinion of it.
Go find one that suits you better, or why mot build your own and prove that you can do better :) -
Related Rants
Why React is soo complicated? Seriously why do we always need to use some stupid shit like this
const [state, setState] = useState();
what the fuck is this? Who designed it that way, why it should always look like shit for no reason? Why its API feels like spaghetti? When i am comparing other front-end frameworks they feel like heaven in their structure.
AND WHAT IS WRONG WITH ME HAVING A QUOTE ON A PARAGRAPH ELEMENT, WHY DO I HAVE TO USE FUCKING HTMLENTITES FROM 2000?
FUCK'ERE
rant
js
react