|
|
|
|
|
by dartos
630 days ago
|
|
> It just returns a tuple. That's not confusing at all and it's a very well established pattern in most modern languages. A few things wrong with this. It does not return a tuple, it returns an array with 2 elements. You, as the react dev, need to just know that this is the case and that one is the value and the other is a set function. In most modern languages, tuples are common, yes. But not in JavaScript. React isn’t a python or go framework, it’s a JavaScript framework.
Why doesn’t it act like almost everything else in js land and return an object with 2 named fields? Why place extra knowledge burden on the developer?
It’s just poor api design Yes useEffect is also a huge complex pain point, but it just takes longer to type out why that is. Pretty much all the hooks are as almost nothing else in the JavaScript ecosystem acts like they do. |
|
The explanation is actually very simple: because in 100% of times you need to give those two fields custom names. It is easier and more concise with tuple:
Than with object + renaming, which quickly gets clumsy when you have dozens of such lines in your component: