Skip to content

Svelte 5: Allow more flexibility for @render tag expressions #9582

Closed
@abdel-17

Description

@abdel-17

Describe the problem

In React, if you have a <Button> component, you can spread its children into a <button> and it works fine.

function Button({ foo, ...props }) {
    return <button {...props} />;
}

In Svelte, we have to do this:

<script>
    let { children } = $props();
</script>

<button>
    {#if children}
        {@render children()}
    {/if}
</button>

It's quite boilerplate-y.

Describe the proposed solution

Allow passing children to HTML elements.

<script>
    let { children } = $props();
</script>

<button {children} />

Alternatives considered

Just keep the current syntax, which is a tad bit boilerplate-y, but not a huge deal.

Importance

nice to have

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions