If the prop array can be an object or a string. Which method would you use ?
This is the code that renders the props.items that prop can be either an array of objects with a text titles and an icon or only an array of text titles.
Also how would you do validation ? The code i wrote works correctly but there's a better way?
<Index each={props.items}>
{(item, index) => (
<A
href={
props.hrefRoot +
(typeof item() === "string" ? item() : item().text)
}
activeClass="router-link-active"
inactiveClass=""
class="carousel-item"
>
<Show when={item().icon}>
<span class={"icon icon-" + item().icon} />
</Show>
{typeof item() === "string" ? item() : item().text}
</A>
)}
</Index>
1 Reply
Looks good to me.