BuilderIO / mitosis

Write components once, run everywhere. Compiles to React, Vue, Qwik, Solid, Angular, Svelte, and more.
https://mitosis.builder.io
MIT License
12.58k stars 563 forks source link

Conditionals not supported? #117

Closed mindplay-dk closed 3 years ago

mindplay-dk commented 3 years ago

Any plans to support conditional expressions with JSX?

image

This is fairly idiomatic - not just to React, but to JSX with most frameworks and libraries.

It looks like you do support loops so I was a bit surprised you don't see to support conditionals - it seems like loops would be more difficult to implement, so maybe this is just a bug?

Either way, loops and conditionals are both pretty essential to building any UI, I think. 🙂

steve8708 commented 3 years ago

Ah! thanks for catching @mindplay-dk! Right now there are two ways to do conditions, ternaries are coming up on my todo list

In the meantime, you can use the facade <Show /> component, like

import { Show } from '@builder.io/mitosis'

<Show when={showName}><input ... /></Show>
<Show when={!showName}>Name editor disabled</Show>

or && boolean operator

import { Show } from '@builder.io/mitosis'

{showName && <input ... />}
{!showName && <>Name editor disabled</>}

Def agree that ternary needs support, will keep this open until added shortly

steve8708 commented 3 years ago

Implemented locally, will be merged soon

Screen Shot 2021-09-06 at 12 54 05 PM
steve8708 commented 3 years ago

Beta support added, if you hit any issues lmk and happy to look into