Update documentation/docs/97-best-practices/10-best-practices.md

Co-authored-by: ComputerGuy <63362464+Ocean-OS@users.noreply.github.com>
best-practices-doc
Rich Harris 2 days ago committed by GitHub
parent 6895611c05
commit 48d101bf36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -54,7 +54,11 @@ to allow `<MyComponent bind:value />`. This can get hairy when the value of the
## Events on elements
Every prop that starts with `on` is treated as an event listener for the element. To register a `click` listener on an element you can do `<button onclick={()=>{}} />` (NOTE: in svelte 5 there's no colon between `on` and `click`). Since elements are just attributes you can spread them, use the `{onclick}` shorthand etc.
Every prop that starts with `on` is treated as an event listener for the element. To register a `click` listener on an element you can do `<button onclick={() => {}} />`
> [!NOTE] In Svelte 5, `on` is no longer a directive, so you can't use `on:event`, you have to use `onevent`.
Since elements are just attributes you can spread them, use the `{onclick}` shorthand, etc.
If you need to attach listeners to `window` or `document` use `<svelte:window onclick>` or `<svelte:document onclick>` instead of using `onMount`/`$effect`

Loading…
Cancel
Save