Skip to content

Svelte Button onclick Binding Fails with Spread Props #16565

Answered by brunnerh
aa89227 asked this question in Q&A
Discussion options

You must be logged in to vote

Without the spread, the access is deferred to within a new function:

button.__click = function (...$$args) {
	$$props.onclick?.apply(this, $$args);
};

With the spread, the handler is accessed more directly, causing the error:

$.attribute_effect(button, () => ({ onclick: $$props.onclick, ...props }));

These are implementation details and it should be considered a pure coincidence that one of the cases does not blow up. You should not use component.hind either way.

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@aa89227
Comment options

@brunnerh
Comment options

@aa89227
Comment options

@brunnerh
Comment options

Answer selected by aa89227
@aa89227
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants