Should I use <Show>?
<div>
{isVisible && <div/>}
{isVisible ? <div/> : <span/>}
</div>
Can't I just use conditional statement ?
Is it same? or Should I use <Show> for performance?4 Replies
https://www.solidjs.com/tutorial/flow_show
here - basically you can use React-style ternaries, but it's considered a good practice to use a Show component in Solid. also, your example is wrong - it should be isVisible(), not isVisible
SolidJS
Solid is a purely reactive library. It was designed from the ground up with a reactive core. It's influenced by reactive principles developed by previous libraries.
Why does solid have so many components that jsx basically has features for built in
Like For and Show
Why is it a “good practice”
Well For and Index are completely different from just
.map
Show is useful for readability and sometimes handling ts narrowing with the callbacksolid doesn't have a vdom. so using
.map
for example instead of <For>
would rerun it from scratch and recreate the dom nodes on every signal update. Same would happen with ternary operators if solid wouldn't explicitly handle them and convert them to basically a <Show>
equivalent