by genezeta · 7y ago · 0 comments
That is that, you could do...
useState("someID")
...and somewhere else (* or in the same place but on a different call) again... useState("someID")
...and this indeed refers to the same item. But using a Symbol, you need to first create it, store it somewhere and then use it. That is, you can't do this... useState(Symbol("someID"))
...because this will fail through different repeated calls. Instead you'd need to first... let someSymbol = Symbol("someID");
...and then... useState(someSymbol)
Or, alternatively, use Symbol.for("someID"), which then has both problems: creating the symbol first and clashing of identifiers.While the article does not explain this clearly, the example used alludes to this in an indirect way.
Personally I do think that this would be a more desirable sacrifice to make than restricting call order, but the React team thinks otherwise, it seems.
Also... a nitpick, but `new Symbol` always throws a TypeError. And Symbol.for() is a useful escape hatch.
I suggest you to take the `useSubscription` example from the "diamond problem" section and try to convert it to your proposed API. I think you'll see why it falls apart.
(Don't forget effects would also need keys.)
Yes, you're right. I was distracted with other stuff and meant just Symbol, without new. I'll fix it. Thanks.
As for the rest... Well, I don't really care much for React and many of the decisions they make. I don't like CSS-in-JS at all, and GraphQL... well, that one's nothing new.