React is getting me in trouble with flexbox because of the wrapping div in a component's render function is throwing off my flex-directions.
From what I understand about React, all the component's jsx elements should be wrapped up in a single div. For example this works:
return (
<div className="com-container">
<div className="other-stuff">
</div>
</div>
)
whereas this doesn't:
return (
<div className="com-container">
</div>
<div className="other-stuff">
</div>
)
Yet this is making things hard with flexbox rows and columns. For example say we had this flex relationship.
<Parent Column Component /> //vertical flex
<ChildRowComponent1 /> //horizontal flex
<ChildRowComponent2 /> //horizontal flex
<ChildRowComponent3 /> //horizontal flex
But ChildRowComponent2
& 3
can be swapped out dynamically - which causes me to refactor by putting ChildRowComponent2
& 3
in their own component but since all rendering must be wrapped up in a single div I get this extra div that messes up the flex directions.
<Parent Column Component /> //vertical flex
<ChildRowComponent1 /> //horizontal flex
<div>
<ChildRowComponent2 /> //horizontal flex now broken
<ChildRowComponent3 /> //horizontal flex now broken
</div>
Question:
Is there a flexbox trick to handle these cases or am I just doing something wrong with how I'm structuring my components?