Live data from Hacker News

Comparing Svelte and React

jackfranklin.co.uk

201–210 of 338 posts

Re: Comparing Svelte and React

#201

I really do not understand the appeal of Svelte, it seems to be making all the same horrendous mistakes as Vue (bad templating/DSL that shoehorns control flow and bindings into DOM representation, esoteric lifecycle hooks etc) and the only advantage it clearly has over other frameworks that I can see is simple components can generally be written more concisely. Are there actually any tangible benefits to using it ove…

Tangible benefits? It's simple.

Re: Comparing Svelte and React

#202

I'm a big fan of Svelte. I've raved about their documentation before, but it bears repeating: this should be the gold standard. You can read it all in a day. There are examples to follow right next to the documentation. Svelte is both succinct and powerful. I find this in contrast to React which is often baffling and incoherent. I say this as someone that has used React professionally for 6 years. They've changed the…

I think many people adopted React because Facebook was behind it, and using it in production, the ecosystem is huge, there is a react- package for everything you can image, there is also react-native, I don't like it, but there it is, you can reuse the knowledge to build native mobile apps. Now Svelte, I haven't been following, but I think the creators are working in what's going to be next and even better framework[…

The main reason people started using React is the JSX implementation in React at the time was very innovative. Actually many people working with Rihno in 2006 has talked about using JSX as templating system. FB is just the first one did it. However, now days there are plenty other less bloated front end frame work such as svelte, vue, mithrill that is more easy to use and have JSX support as well. There is really no reason to use React now days.

Re: Comparing Svelte and React

#203

I'm a big fan of Svelte. I've raved about their documentation before, but it bears repeating: this should be the gold standard. You can read it all in a day. There are examples to follow right next to the documentation. Svelte is both succinct and powerful. I find this in contrast to React which is often baffling and incoherent. I say this as someone that has used React professionally for 6 years. They've changed the…

But it's not JavaScript. It's something similar to JavaScript.

Re: Comparing Svelte and React

#204
post #23

Earlier quoted context omitted.

Please don't. It looks awful. And I think it's not necessary. Typescript should inherit it's type depending on what you are passing into "users".

I assume you don’t like invocation? That’s not the point here. In svelte you can’t* define type variable that’s bound to the same type in whole component. I can’t enforce that properties `items` is `T[]` and `selectedItem` is `T`. * Last time I checked. I could be wrong now.

I'm writing about and not about Svelte. I don't know anything about Svelte except what I just learned in the article. I just don't like the syntax of /> and favour instead, because Typescript will inherit it's generic type from users={...}

See my example here: https://codesandbox.io/s/clever-neumann-89tnx?file=/src/App....

Re: Comparing Svelte and React

#205
post #46
post #23

Earlier quoted context omitted.

Please don't. It looks awful. And I think it's not necessary. Typescript should inherit it's type depending on what you are passing into "users".

There are valid reason to do that. Like a component that takes render function and item that is passed into it that can be anything.

You can do that, but you don't have to.

See my example here at line 26: https://codesandbox.io/s/clever-neumann-89tnx?file=/src/App....

Typescript will inherit the type automatically.

Re: Comparing Svelte and React

#206

I'm a big fan of Svelte. I've raved about their documentation before, but it bears repeating: this should be the gold standard. You can read it all in a day. There are examples to follow right next to the documentation. Svelte is both succinct and powerful. I find this in contrast to React which is often baffling and incoherent. I say this as someone that has used React professionally for 6 years. They've changed the…

I agree with your impressions. When I first started working with react professionally one year ago I was thinking I was dumb for not being able to find the logic behind the different moving parts. Now I know that there's none.

Re: Comparing Svelte and React

#207
post #84
post #53

How's unit testing in Svelte today? That's the main worry I have with template-based systems (well, that and TypeScript support, but I hear that that's quite OK now).

There’s svelte-testing-library [0] which follows the same approach as the React flavor. It emphasizes testing the app “as the user would use it”, which boils down to rendering components and inspecting the DOM. They intentionally don’t give you visibility into the internal state of the component, which can be weird to get used to if you’re used to doing things like “click the button; assert that state isClicked becam…

Thanks, that looks pretty good, and testing-library is excellent. I couldn't find it in the docs, but do you know how this "renders" the Svelte components - in memory using e.g. jsdom, or by firing up a full-fledged browser? (The former would be highly preferable.)

Re: Comparing Svelte and React

#208
post #186
post #53

How's unit testing in Svelte today? That's the main worry I have with template-based systems (well, that and TypeScript support, but I hear that that's quite OK now).

It's not great as other people have mentioned. But I think storybook is a good middle ground for testing (it might be a stretch for others to see it that way) and Svelte has awesome support for storybook.

Storybook is neat, and very useful for automated smoke tests, but I wouldn't want to write extensive unit tests that rely on firing up an entire browser - far too flaky to my liking.

Re: Comparing Svelte and React

#209

Earlier quoted context omitted.

When it comes to primitives you can only pass by value, but with objects and arrays you can only pass by reference . And this applies to comparisons too: when comparing objects or arrays you are comparing by reference , not deeply by their inner values. If you want to compare them deeply you have to take some additional steps to make that possible, and all of the different strategies for doing so have different trade…

You don't pass by reference in JS. You pass references by value. Passing by reference has a well defined meaning in computer language terminology. It means passing something that references the variable outside the function. Something you can't do in JavaScript void someFunc(ref int v) { v = 456; } var foo = 123; someFunc(foo); write(foo); // output 456 Above we are not passing 123 (the value of foo) into someFumc, w…

Great explanation of something that has caught me out multiple times (I occasionally dabble in JS).

Having spent my career in languages with pass by reference it feels unnatural not to have it. I suspect if I started with JS this wouldn't be such a problem.

Re: Comparing Svelte and React

#210
post #86

Earlier quoted context omitted.

How is Svelte "just JavaScript" when it uses custom templates and file types?

I feel like this "just javascript" trope really needs to die. JSX is not "Just Javascript", and magically reactive `foo = bar` assigments are not "Just Javascript". But frankly, that doesn't really matter one bit anyways; it's fairly nitpicky to object to different control flow syntaxes, when at the end of the day you're just rendering data from a request to screen. I'm sure not many people would be willing to argue…

> JSX is not "Just Javascript"

It's very thin syntactic sugar over a function call. It has a very simple 1:1 mapping to the output code, as opposed to "magically reactive `foo = bar`.

> I'm sure not many people would be willing to argue that throwing promises (as react suspense supposedly does) is a holy grail of frontend development, even though it is "just javascript".

I'll give you that hooks and suspense are straying further from normal js because they don't behave like normal functions do and have special rules for being called; hooks are a DSL for encoding incremental computations into js, and suspense is just the react team fawning over algebraic effects/delimited continuations and trying to reproduce them in js.

But then again, all of these can be defined in normal JS code as opposed to a DSL which compiles to who knows what, so all the rules applying to normal JS and its tooling apply to them.

Post reply on HN