Replies: 2 comments 5 replies
-
I wrote a long explanation I was quite happy with, with code examples but it seems to have been lost (I guess I never hit "comment"). So I will try to do this again.
<ul>{ mapArray(
() => props.list,
item => <li>{item.description}</li>,
{ fallback: () => <Empty /> }
) }</ul> <ul>
<For each={props.list} fallback={<Empty />}>
{ item => <li>{item.description}</li> }
</For>
</ul> This is easier to show and leaves less room to make accidental mistakes of omission. There is also a slight benefit that since it's a component Solid can also be a little smarter with its heuristic that actually reduces reactive wrappers. We save one on the expression that wraps the |
Beta Was this translation helpful? Give feedback.
-
I would say that JS is perfectly good for fine-grain reactivity but JS is not well suited for expressing rendered content in a declarative way that is easy for authors to understand. HTML is generally acceptable for describing this with the added advantage that it the platform language on the web; however, it fails to adequately express much more than static content. This mismatch is why all the major UI libraries use some DSL be it JSX in React or Vue's template language. I'm not entirely clear what you mean by mismatch, or how Solid violates JSX "purity". I would actually argue Solid pushes authors toward putting more of the view logic within the JSX template thus reducing its distribution throughout the codebase. The example above looks like a typical React component which tend to be a JS function that returns some JSX, or in other words a mix of JS and JSX. In React, because component functions re-execute due to state changes your example renders the different greetings in response to Technically your example works fine, but likely not as you expect because |
Beta Was this translation helpful? Give feedback.
-
The selling point of jsx, AFAIK, was: we already have a language for logic and control flow, let's not program in an awkward sgml dsl.
If one buys into that notion, combining js with sgml for logic and control flow is unappealing.
The docs mention that otherwise, "This means helper functions." Ok, what's wrong with helper functions, assuming they can get the job done? Perhaps there should be both? Either way its a dsl, but a js dsl seems preferable to an sgml one, when you're already in js.
Beta Was this translation helpful? Give feedback.
All reactions