4 ms·
I'm inclined to agree on all these points, but I do end up doing most of these things now, in one way or another. For loops I'll create a collection of items i
by dcd0101 10y ago
I'm inclined to agree on all these points, but I do end up doing most of these things now, in one way or another.
For loops I'll create a collection of items in a function (usually done with map against a prop collection) and drop that variable in my JSX.
Basically the same for conditionals. If I want a thing, a var gets a component assigned. Otherwise it's null.
Are these bad patterns, as is?
- jameslk 10y agoNo, these are good patterns. You've taken an otherwise large chunk of code and broken it down into comprehensible pieces that can be composed together and tested individually. This also leads nicely into refactors, where you can extract these smaller chunks into new components when your old component is handling too many responsibilities. Unfortunately if control flow gets bolted onto JSX we can expect to see a lot less of this. Others will assume that this is the way business is done. That is, creating hundreds of lines of hard to follow conditionalized pseudo XML. I realize this already occurs in more bastardized forms, but it shouldn't be encouraged by new language features.
- gbog 10y agoYep, how do we vote against logic inside jsx markup?