|
|
|
|
|
by doctor_eval
861 days ago
|
|
Because it’s introducing a magic global compiler directive - $props - that’s unique to Svelte. Everyone knows what export let prop = 10
means. But what’s $props? It’s a magical invocation (literally, a rune) of a compiler directive. So while it’s valid JS, it’s actually a signal to the compiler, with special behaviour. It’s something you need to learn and understand beyond just JavaScript.Also, to your point, it’s not actually destructuring. This statement is declaring “prop” as a new property. And finally, this statement actually does export “prop” to a user of the component. But that’s no longer explicit. |
|
> export let prop = 10
> means.
What? I mean that's technically syntactically correct JavaScript but it makes no sense outside of Svelte, and if the prop is not literally named prop like in your example here, it's much harder to understand what this is doing compared to taking a prop value out of a $props object (or rune or whatever), like you would in many other frameworks.
I'm just a bit surprised because while I like Svelte I feel like all of is like this, it's all technically JavaScript syntax but all of it is magic that only works through the Svelte compiler, and this new syntax actually looks slightly less so to me, although I wouldn't say I prefer it.