Live data from Hacker News

Comparing Svelte and React

jackfranklin.co.uk

241–250 of 338 posts

Re: Comparing Svelte and React

#241
post #205
post #46

Earlier quoted context omitted.

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.

That's amazing, thanks for the tip

Re: Comparing Svelte and React

#242
post #155
post #151

Earlier quoted context omitted.

But I wish new frameworks stayed away from inventing new language syntax. Not only is it a cognitive burden on programmers, it throws all the tooling off. From Svelte: {#each cats as { id, name }, i} JavaScript already has facility for loops and mapping, and relying on that will automatically get you tooling/IDE support. React handles this aspect quite well, and to me that's a point in favor of React. I do agree with…

I agree that gratuitous syntax differences are tiring, but in this case, there's actually a very good reason why it's not just using JS. When it comes to reactive systems, you need to be able to statically analyze control flow structures in order to compile to efficient code. In JS, a for loop is a loop, but so is array.map, Object.keys and someLib.each. The loop could be hidden three layers deep in a higher-order fu…

> Dealing with this sort of complexity when writing optimizing compilers is very very hard

Which is why we use JS and allow V8/SpiderMonkey/JSC to do it for us :)

Re: Comparing Svelte and React

#243

Earlier quoted context omitted.

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[…

It's so boringly cynical to suggest that people use something because they're lemmings rather than any of the great reasons to use something. Go watch the original React debut talk and ask yourself if React had/has anything going for it beyond Facebook's backing. I know I, and most developers I know, dropped Backbone/Knockout/whatever instantly to use React because it was so obviously better. Now that unidirectional…

I went to one of FB's early internal meetups about React and I was initially skeptical of JSX but very excited by what it offered.

I was working at Groupon and using Backbone at the time and found nesting components to be a major hassle. We used a framework called Thorax on top of Backbone, which helped but still fell far short of React's convenience.

Re: Comparing Svelte and React

#244

Earlier quoted context omitted.

Sounds like you're describing Vue. Is their any substantial advantage over Vue that you're aware of? I think a lot of people, including myself, are just uninterested in arbitrarily and subtley different solutions to the same problem. I've used react, and it's just not as compelling as anyone made it out to be. Neither is Vue compared to React for that matter, but it appeals to me a little more.

So I'm a Vue developer who hasn't ever actually built anything in Svelte, but Svelte uses a really cool model that's completely different from Vue and React. Where Vue/React use a virtual DOM, Svelte is compiled to essentially vanilla JS. Instead of having render functions that fully replace a component, Svelte updates just the parts of the DOM that need to be updated. Because of the dramatically reduced overhead, pr…

> Svelte is compiled to essentially vanilla JS

How does this scale to anything remotely complex?

I've found that if you have a decent knowledge of React it's hard to make anything slow with it.

Re: Comparing Svelte and React

#245

Earlier quoted context omitted.

The problem with Redux is two fold: 1. The datastore is a massive global. This already brings to it many of the pitfalls that have caused programmers everywhere to avoid global variables like the plague. But in addition to that, for incredibly complex apps, it is a massive burden to maintain all of your state in one place, without any ability to encapsulate or localize trivial local states. Why do I need a global sta…

Note that we have _always_ advised that you should avoid putting literally every piece of state into the Redux store, and we do _strongly_ encourage keeping local state in components: - https://redux.js.org/faq/organizing-state#do-i-have-to-put-a... - https://redux.js.org/style-guide/style-guide#evaluate-where-... - https://redux.js.org/tutorials/essentials/part-2-app-structu...

Which goes to the point that redux is not perfect and has its own downsides. I generally take the simplest solution to solving a problem and favor readability over abstraction whenever possible.

Re: Comparing Svelte and React

#246
post #86

Earlier quoted context omitted.

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 stra…

> compiles to who knows what

You can easily read the compiled Svelte output and see how each piece of template is wired to the state. There is very little cruft in it, and no real runtime library to speak of.

The debugging experience (not that I have needed it much) is light years ahead compared to going through React's internals.

Re: Comparing Svelte and React

#247

Earlier quoted context omitted.

> 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 stra…

> compiles to who knows what You can easily read the compiled Svelte output and see how each piece of template is wired to the state. There is very little cruft in it, and no real runtime library to speak of. The debugging experience (not that I have needed it much) is light years ahead compared to going through React's internals.

Yeah, but it's still a DSL and that means that I can't be sure that everything I can normally do in JS is valid there, and external tooling won't be able to make sense of it without additional work.

Re: Comparing Svelte and React

#248

No mention of Typescript. You'd be mad to consider writing a significant app without it, and React has really great Typescript support - even templates are type checked properly thanks to JSX/TSX, and basically all tools support JSX these days. Vue doesn't come close to that, but it does look like Svelte is at least a bit better: https://svelte.dev/blog/svelte-and-typescript I'd still be wary that there are big cavea…

> Vue doesn't come close to that > thanks to JSX/TSX, and basically all tools support JSX these days I haven't used TS and Vue together, but Vue 3 seems to have been written with TS, as well as having supported JSX for quite a while. What are the limitations?

It doesn't type check templates properly.

Re: Comparing Svelte and React

#249
post #86

Earlier quoted context omitted.

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 stra…

I should also explain what I mean by "thin syntactic sugar": JSX is a local transformation which doesn't need any external context to be translated to plain JS. `Hello` will always compile to `React.createElement('div', { greeting: "hello" }, "Hello")` no matter what; in Svelte, `count += 1` will output different code based on its context because it will compile the whole component as a single unit.

Re: Comparing Svelte and React

#250

> writing complex React components feels more like admin; a constant worry that I'll miss a dependency in my useEffect call and end up crashing my browser session. I don't understand this worry, but I guess that happens when you try to do everything with hooks, the way I settled in my approach is to use React components just for the view without hooks, nor lifecycle logic, just dumb components with ocasional local st…

This just proves how insane things have become.
Post reply on HN