Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Once a data is transformed into a view in Svelte, you can't do anything with it in JS. For example, a component can't iterate over the children in a slot [1].

This is limiting when designing generic Component-APIs.

As an extreme example: In React, I could trivially define a tabbed interface by mixing strings, JSX, and components, without imposing any DOM-structure. The component that reads this definition could use it to build a tabbed-view on mobile, and a master-detail-view on desktop. ...or it could build a table of contents. When defining the tab names, I can mostly use strings, but fall back to JSX if necessary. Importantly, the API is completely independent from the implementation.

    const tabs = [
       { name: "Tab 1", icon: <img ... />, content: MainTab },
       { name: <>Tab with <b>bold<b/> text</>, icon: <MyIcon ... />, content: SecondTab },
    ] 

    return <MyLayout tabs={tabs} />
[1]: https://github.com/sveltejs/svelte/issues/5381


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: