We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
prefer-event-forwarding
In our dev team, some devs tend to redefine event handlers as props which makes code more verbose than it needs to be.
Button.svelte
export let onClick = () => {} ... <button on:click={onClick}>Click me</button>
Instead, we can rely on event forwarding like this:
Button.svelte // no onClick prop ... <button on:click>Click me</button>
See more: https://learn.svelte.dev/tutorial/event-forwarding
The rule should report on props that mirror native HTML event handlers and suggest simplifying them with event forwarding.
<!-- ✓ GOOD --> <button on:click>Click me</button> <!-- ✗ BAD --> <script> export let onClick = () => {} </script> <button on:click={onClick}>Click me</button>
No response
The text was updated successfully, but these errors were encountered:
Svelte 5 is moving into direction of using props for event handlers:
Instead of doing to 'forward' the event from the element to the component, the component should accept an onclick callback prop:
<script> let { onclick } = $props(); </script> <button {onclick}>Click me</button>
https://svelte-5-preview.vercel.app/docs/event-handlers#bubbling-events
So although I agree that using on:click forwarding in Svelte 3 & 4 was nice and preferable, It will make upgrading slightly harder.
on:click
Sorry, something went wrong.
Non the less is Svelte 4 supported for the foreseeable future. So I think this should be considered.
No branches or pull requests
Motivation
In our dev team, some devs tend to redefine event handlers as props which makes code more verbose than it needs to be.
Button.svelte
Instead, we can rely on event forwarding like this:
See more: https://learn.svelte.dev/tutorial/event-forwarding
Description
The rule should report on props that mirror native HTML event handlers and suggest simplifying them with event forwarding.
Examples
Additional comments
No response
The text was updated successfully, but these errors were encountered: