3 ms·
Couldn't a custom hook have a map of maps that keep track of this? The first map gets the symbol that was passed to the custom hook as keys and the maps inside
by k__ 8y ago
Couldn't a custom hook have a map of maps that keep track of this?
The first map gets the symbol that was passed to the custom hook as keys and the maps inside that map would use symbols only the custom hook knows about.
I think your solution is superior in that is more concise and I at least think I understand why you went that way. I'm just trying to understand why the symbol approach wouldn't work.
- danabramov 8y agoYeah you could do this but this “breaks copy paste” (one of the flaws). We want creating a custom Hook to feel exactly like extracting a function. It should feel easy and you shouldn’t need to mess with maps and symbols.
- k__ 8y agoOkay, DX is an important selling factor, so your approach seems reasonable to me.
- danabramov 8y agoRuntime performance is another one. Map lookups aren’t free, especially if there’s a whole bunch of them happening in every component on every render.
- k__ 8y agoYes, the order restriction buys a lot of things rather cheaply. And while I trust the React teams judgement, I teach people React and they often question the "why".