question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Events in spread props

See original GitHub issue

Is your feature request related to a problem? Please describe. At the moment, there is no way to manage component events for a dynamic component, with spread props. Let consider this example:

<script>
	const props = {
		'label': 'Click me'
		'on:action': () => {}
	}
</script>
<svelte:component this={Comp} {...props} />

on:action will not be called.

REPL here

Describe the solution you’d like To have the code above working 😊

Describe alternatives you’ve considered The workaround is to consider callbacks instead of events, like this :

<script>
	const props = {
		'label': 'Click me'
		'onAction': () => {}
	}
</script>
<svelte:component this={Comp} {...props} />

But then the code in Comp must be different compared to a normal dispatch usage.

How important is this feature to you? It’s just annoying because the workaround works pretty well, but maybe it can be a useful feature to keep consistency with the spread props.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:23
  • Comments:19 (4 by maintainers)

github_iconTop GitHub Comments

10reactions
rgossiauxcommented, Jan 6, 2022

I also find this annoying & a source of clunkiness in the framework. The ergonomics of on: are lacking in just about every way & it’s hard to work with programmatically. I wish these issues got a lot more attention as they’re clear areas where Svelte’s DX is worse than React’s.

5reactions
afaurcommented, Aug 9, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

Events in spread props • REPL • Svelte
Interactive Svelte playground.
Read more >
JSX Spread Operator <Component {…props} /> Meaning
If you already have props as an object, and you want to pass it in JSX, you can use ... as a “spread”...
Read more >
Transferring Props | React
You can use JSX spread attributes to merge the old props with additional values: <Component {...this.props} more="values" />. If you don't use JSX, ......
Read more >
Is there any method to "spread" only the Synthetic events ...
rest props. I know your recommendation is a small effort but in my opinion, it is much cleaner and efficient to have a...
Read more >
Passing Props to a Component - React Docs
Use spread syntax with restraint. If you're using it in every other component, something is wrong. Often, it indicates that you should split...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found