|
|
|
|
|
by lhorie
3419 days ago
|
|
Refactoring into functions/components doesn't magically make a complex ternary tree go away. It helps the body of each branch be less noisy but the ternary tree will still be there. You're talking about taking something like `foo && bar || baz && quux` and turning it into `isSomeCondition()`, but that's a pretty obvious refactor in any templating system. I'm talking about things like return (
<div>{
x.type === 'foo' ? <Something/> :
x.type === 'bar' ? (
<div>
<h2>More stuff</h2>
<Another data={x.data}/>
</div>
) :
x.type === 'baz' ? <Another data="baz"/> : null
}</div>
)
At this point, I think it's perfectly valid to have the opinion that JSX isn't helping much, since the JS-to-HTML ratio in this case is relatively high.Refactoring would just make it more difficult to mentally piece things back together given you would end up with sparse component instantiations scattered amidst otherwise-procedural js code, as opposed to the more ideal single-root, declarative virtual dom tree. |
|