by bryanlarsen · 11y ago · 0 comments
One of the nicest things about designing a React app is that React makes it so easy to divide your app up into tiny little components that compose and reuse well, and are really easy to understand. Where an angular app might have 5 different controllers and accompanying templates, a similar React app might have 50 different components.
One of the reasons that it's so easy to split off a new React component is because JSX is inline. Putting that into a separate file increases the impedance and maintenance burden substantially.
In other words your
var createItem = function(itemText) {
return <li>{itemText}</li>;
};
return <ul>{this.props.items.map(createItem)}</ul>;
Is much more likely to be: return <MyList items={items} />;
who wins now?When writing Angular code I'm always fighting to make things simpler than the system wants, trying to break my code up into more distinct components, and only after refactoring or hitting my head against the wall settle on the more complicated (but fewer in number) representation.
That is, I think, why the comparison between the two is valuable: not because they are libraries that fill the same niche, but because they encourage distinct development styles.
That said I never got over wanting nicer if/looping in JSX - if anyone else wants that compromise you can use the library I made to do it: https://github.com/valtech-au/jsx-control-statements.