Skip to content

Spread Props for on:<event> directives #7625

Closed
@ecoinomist

Description

@ecoinomist

Describe the problem

Currently it's possible to spread only non-event props, because on: and other directives, such as bind:, do not work inside a spread object.

Example REPL.

Use case: I'm converting an existing application from React that creates UI from JSON files to Svelte. Events, such as onChange, onClick are created dynamically at runtime and passed to components during their render lifecycle using spread props (for encapsulation/abstraction purposes due to recursive nature of the framework).

Describe the proposed solution

Enable spread props for all prop directives, including modifiers, so that this code would work:

<script>
  let props = {'on:click|once': (e) => {alert(e)}}
</script>
<div {...props}>Click Me</div>

Alternatives considered

Enable spread props for event bindings without directives

<script>
  let props = {'onClick': (e) => {alert(e)}}
</script>
<div {...props}>Click Me</div>

Importance

i cannot use svelte without it

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions