4 ms·
You can add do-expression proposal support in .babelrc: <div> {do { if (user) { <Logout /> } else { <Login /> } }
by hombre_fatal 5y ago
You can add do-expression proposal support in .babelrc:
<div>
{do {
if (user) {
<Logout />
} else {
<Login />
}
}}
</div>
https://babeljs.io/docs/en/babel-plugin-proposal-do-expressions https://babeljs.io/docs/en/babel-plugin-proposal-do-expressi...
- Izkata 5y agoOr, no need to enable anything: {user ? <Logout \> : <Login \> }
- couchand 5y agoOk this thread just reached peak JavaScript.
- christophilus 5y agoTernary expressions have been around long before JavaScript was a twinkle in Brandon Eich’s eyes.
- 9wzYQbTYsAIc 5y agoJust modern ECMA Script, not peak JavaScript. ES6 and React Hooks have fully sublimated the web development landscape.
- hombre_fatal 5y agoYes, my example is trivial, but if-else can easily outgrow the ternary. The do-expression lets you embed arbitrary statements.