3 ms·
> DSL: JSX is a DSL - I can't remember the last time I've seen someone use && as a poor man's if statement, or ternary statements dozens of lines long until I s
by mlsarecmg 9y ago
> DSL: JSX is a DSL - I can't remember the last time I've seen someone use && as a poor man's if statement, or ternary statements dozens of lines long until I started writing JSX. JSX is neither idiomatic JavaScript nor HTML.
Nothing in React forces you in any way to use ternaries. You can do all your pre-calculation in the render method, and if that's your style you would most certainly do that.
const Say = ({ reverse, text }) => {
if (reverse)
text = text.split('').reverse().join('')
return <div>{text}</div>
}
<Say reverse text="hello" />
Btw, Vue isn't any different here, you use ternaries there as well, only that it's severely limited as you couldn't refer to other components, the template is a dead string after all:
template: `
<li v-for="(item, index) in items">
{{ index > 2 ? item : item.split('').reverse().join('') }}
</li>`
> It demands immutability, which JS has no native support for.
It doesn't do that at all. Even redux uses plain shallow copies. Vue on the other hand does exactly that, it uses observables which aren't supported in most browsers. Reason why as of version 3 you will maintain two codebases (one for IE11 and prior, one for evergreen) since Proxies aren't back-compatible.
> it wants you to use FP
Not at all. It is unopinionated.