Events in spread props
See original GitHub issueIs 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.
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:
- Created 3 years ago
- Reactions:23
- Comments:19 (4 by maintainers)
Top Results From Across the Web
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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.@devongovett Here is a use action example: