Replies: 2 comments 1 reply
-
You can make use of fallbacks in destructuring props to achieve something similar to this. |
Beta Was this translation helpful? Give feedback.
1 reply
-
My suggestion is to always use camel casing for custom events (callbacks) to intentionally avoid collisions with HTML events, which all seem to be in lowercase. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've been Svelte-ing for a while now and I just ran across something in Svelte 5 that took me a while to debug.
All DOM event handlers are case sensitive in Svelte 5
This is fine for most scenarios where you have a simple
onclick={...}
but when you're passing lots of props to components that need to be added to elements using spread props, this gets incredibly messy an error prone. Which leads me to the question - should we be naming all event handlers with lowercase?I like to name event handlers using camelCase, especially for components. E.g. "onUserLoggedIn". However I pass a lot of props using spread props in order to make it easy to customize components later on. This means I'm likely passing event handlers down multiple levels of components which leads to needing to write cursed code such as:
E.g.
I'd really prefer to continue using camelCase for my event handlers, but it's starting to seem like the best practice is to use all lowercase. What do others think?
Alternatively, I could stop passing spread props for all event handlers I know I care about, but this is a real productivity killer.
E.g.
Beta Was this translation helpful? Give feedback.
All reactions