Svelte’s most annoying feature is if you want something reactive, put a $: before it. That’s the job of the damn framework! If I need to manage reactivity, I might as well write jQuery. React just works and has become mature. I tried Svelte and got pretty turned off by a few things. I urge people to the out their excellent tutorial, until atleast half way through to form an opinion. Don’t just jump on the new JS framework bandwagon.
Hmm. I'm not sure whether that's correct. $: is comparable to Vue's computed instead of a reactive value. Any variables in the component are automatically reactive. External Stores are reactive with a $ prefix.
Yeah, I know nothing about frontend frameworks (Angular was just getting started last time I did any frontend work), and having read about Svelte for the first time just now, the "$:" thing seems pretty reasonable to me.
<script>
let count = 0;
$: doubled = count * 2;
</script>
<p>{count} doubled is {doubled}</p>
I'd be very confused if `doubled` were to somehow automatically update any time the value of `count` changes, if merely defined as a standard variable (e.g. `let doubled = count * 2;`). This would totally break my mental programming model.
I'm not sure what the parent commenter had in mind as an alternative, or how it could be made simpler or terser.
You absolutely have to be conscious of reactivity and how that stuff works in React as well. This is complexity that you as a dev have to deal with in some way.
Svelte and React makes different tradeoffs in how they expect developers to deal with this.
Personally I think maybe Svelte makes a better tradeoff. I've seen so many people make variables instead of using useState, etc… because that's the kind of thinking they're used to.
In Svelte that would simply work for the simple cases, but you'd have to use $: someVar for the more complex cases. I think requiring having to deal with that complexity only when you need it is a more reasonable way to do it compared to React.
Well there are pros and cons, although I would not use Svelte for serious project I hope you cannot deny that it is awesome for small thing, giving you a bit more than just pure JavaScript.
Main advantage I see is size, SPA build with few pages, will be a around 50Kb-100Kb and footprint of the project is of a similar size. Meaning super fast loading on a web page.
Same size of the project in React will take 100Mb of drive space, and something more serious in industrial environment goes easily over 1Gb of disk storage, although I love React I find that insane. Even "Hello World" build of React will range between 2MB and xxMb depending on config.
This just shows you haven’t actually tried writing code with it. Variables are reactive without the $ when used in templates. You only need it for derived expressions.
If you think reactivity is the frameworks’ job I see no reason to praise React at all - especially with hooks you will be manually handling dependencies and updates everywhere, feels like a huge step back.