Brand new going through the tutorial. Unsure of the purpose of the <Dynamic> component.
I feel like I'm missing something obvious. The tutorial page for the <Dynamic> component introduces it as a more compact alternative to a bunch of <Show> or <Switch> components. The "Solution" to the code wants me to replace a
<Switch>
with <Dynamic component={options[selected()]} />
. But why do I even need <Dynamic>
? See the full code below.
Is it just a helper so it's easier to pass props? I come from React, so I would typically build a props object and spread it, i.e.
6 Replies
Dynamic allows changing the component if selected changes. IIRC that's the only functional difference
Sure, but
{ options[selected()] }
seems to also do that? Like, I don't notice any functional difference with and without using <Dynamic>True, but to pass props, you need jsx
And for jsx, you can't update the component used without dynamic
So, the "react" method that I referenced at the end of my post - would that not work in Solid?
It would, so long as you you're fine with ColoredThing remaining whatever it was when options[selected] got read
You would be unable to update the component used if you were to use that method
Ah, ok. That makes sense then. I think the tutorial would be better motivated if there were some props you had to pass, and maybe it would be better not to frame it as simply being a more compact form of Show and Switch. Thanks for the help!