|
|
|
|
|
by xpl
628 days ago
|
|
> Why doesn’t it act like almost everything else in js land and return an object with 2 named fields 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: const [text, setText] = ...
Than with object + renaming, which quickly gets clumsy when you have dozens of such lines in your component: const {value: text, setValue: setText} = ...
|
|
Especially in our world where strong typing is something preferable.
Fewer characters at the cost of clarity is poor api design. Implicitness is almost always worse than explicitness.
Explicit !== clumsy
And again, almost nothing else in the js ecosystem behaves like this. Especially at the time of the big hooks update to react.
Also, again, it’s not a tuple. It’s an array with 2 elements. JavaScript does not have tuples or the semantics for interacting with them as such. You just need to know that there’s always going to be 2 elements.
That extra knowledge burden is the hallmark of poor api design.