3 ms·
You can have global singletons in React too that trigger events without passing them through the component hierarchy. It's just not clean design in my opinion.
by thomashop 5y ago
You can have global singletons in React too that trigger events without passing them through the component hierarchy. It's just not clean design in my opinion. The same reason we avoid global variables in most applications, frontend or not.
If you want to go for a sane way of managing global state you can use redux or context which don't require you passing state up and down the component hierarchy. But in my experience, usually when you design your hierarchy and your data well it makes most sense actually using the hierarchy to your advantage.
There's something fractal about it where the higher-level components deal with higher-level state and problems. In the case of the map you have a shared state between the map and the controls which should be explicit in my opinion and not hidden in one of the components' html data attributes.
The more complex applications I develop, the more appreciate the concept of having a "single source of truth" and not sprinkling states in child components.
- kristopolous 5y agoRight, I claim that limitation was self-imposed and then they found out how unreasonable it was so now they have multiple workarounds in order to emulate the functionality you'd get without them there at all. So instead of the direct path, now you are doing a much more complicated circuitous path because the orthodoxy had to be amended. Again, you're going to say this is good and I'm going to say it's bad. I see a problem where you see a solution. This is not reconcilable, that's why there's so many different programming languages. There's no right answer here and I'm ok with merely having a collection of opinions. It's like politics and religion. Whatever, people are different.