With prop drilling how do you get the setter methods into C3? You have to prop drill all the way down.
Let's say I add a new component under C3 that has a side effect in some sister hierarchy under B. Then now suddenly in between and B and C3 and the other component I have to modify EVERYTHING to take that new change into account and these components now all have an extra prop that they don't intrinsically need but they keep in order to account for C3.
Because data is so intrinsically linked with components Every component between B and C3 now needs to be modified to prop drill when previously it wasn't needed.
This is true of any basic function call hierarchy. Lots of functions in every program's call tree are just passing around values they don't explicitly need but that some callers deeper in the call tree will need, so what you describe is a solved problem at its core: to avoid having to explicitly pass parameters that you don't use around, and having to modify whole call trees when those parameters change, lift those parameters into a data type. Then changes to parameters only have to be made in two places: the data type definition to add a field, and the initialization point to in initialize that field.
Right but the problem here is that you have two hierarchies in react.
You have the HTML hierarchy which is the GUI, and then you have to force data to follow that hierarchy, when really only two components are relevant here. But with react you have to prop drill things all over the place.
But the hierarchy is arbitrary. It's dependent on how you structure the GUI. You're saying to deliberately not let the GUI have deep structures such that the data won't need to prop drilled? That's unreasonable. Complex GUI's will inevitably have complex nested structures with many things that cause side effects.
That's the problem. Data is coupled with GUI. React can't uncouple it.
> Complex GUI's will inevitably have complex nested structures
Not really.
And that's the thing: while this is the usual way, it doesn't have to be! But it does require a shift in mindset from the traditional way people partition components in React.
All I'm saying it is possible to structure the component hierarchy in a way that is independent from what the GUI looks like. By not having a deep hierarchy, you don't have "deep hierarchy problems".
>And that's the thing: while this is the usual way, it doesn't have to be! But it does require a shift in mindset from the traditional way people partition components in React.
So I'm forced to follow the mindset of making the GUI less nested and less complex because data flow requires it? I don't like it.
I prefer to be able to do anything I want with the GUI. The complexity of GUI and the complexity of dataflow should be completely independent.
>All I'm saying it is possible to structure the component hierarchy in a way that is independent from what the GUI looks like. By not having a deep hierarchy, you don't have "deep hierarchy problems".
Isn't it better to have components also independent of logic and side effects? Why am I forced into some specific structure for the sake of data flow? I still don't like this option. I want these concepts decoupled.
> I prefer to be able to do anything I want with the GUI
I didn't say you don't need to stop doing "complex GUIs". What I'm challenging is the assertion that "Complex GUI's will inevitably have complex nested structures". This is not true IME.
> The complexity of GUI and the complexity of dataflow should be completely independent.
And this is exactly what my suggested method achieves. But I'm doing this by going one step further and decoupling the visuals from the component hierarchy. I'm still separating parts of the page into components, I'm just using an alternative to deep hierarchies, and forcing myself to have better reusable abstractions rather than single-use components. I do this with richer primitive components and layout components. That's it.
> Isn't it better to have components also independent of logic and side effects?
This is exactly what I am proposing. What I propose requires keeping logic and side effects from the reusable components. All I'm saying is that the logic shouldn't be distributed among multiple small components, because there's no intermediate layers with single-use components. If you do this, there's no need to worry about the organization you complain about.
In a gist, it's more "Philosophy of Software Design" and less "Clean Code", but applied to React.
> Component hierarchies fundamentally tied with HTML and CSS
Once again: no, not necessarily, and definitely not fundamentally. Perhaps that's where you can't see where I'm coming from.
You can have more than one DOM level per component, and you can also have children/slots. Components don't even have to render anything. Thus GUI and dataflow can be 100% decoupled.
What I mean with all of this is "keep the React component hierarchy flat and use layout and richer primitives that will render THE SAME nested DOM that would be rendered using nested React component hierarchy".
The point is not changing which and how the final DOM looks like, or the design. The final HTML can and will stay EXACTLY the same with a flatter component architecture.
However this example has decoupled component hierarchy and HTML hierarchy. Which demonstrates they don't have to be coupled.
> But this is just bundling the props on a component and using the component itself as a bundle to drill down.
But there is no prop-drilling needed, as long as NavTree and ContentArea are also UI primitives. If you need NavTree and ContentArea to communicate with each other, for example, they're now siblings in the hierarchy, even though the HTML hierarchy is as deep as it needs to be for the design.
Btw: If "NavTree" and "ContentArea" are not primitives, they're the kind of thing that breaks a flat hierarchy and require prop-drilling/context/redux/etc in the first place. This is where one would use configurable primitive components, rather than the "Clean Code"-style extracted code.
With prop drilling how do you get the setter methods into C3? You have to prop drill all the way down.
Let's say I add a new component under C3 that has a side effect in some sister hierarchy under B. Then now suddenly in between and B and C3 and the other component I have to modify EVERYTHING to take that new change into account and these components now all have an extra prop that they don't intrinsically need but they keep in order to account for C3.
Because data is so intrinsically linked with components Every component between B and C3 now needs to be modified to prop drill when previously it wasn't needed.