Live data from Hacker News

Comparing Svelte and React

jackfranklin.co.uk

261–270 of 338 posts

Re: Comparing Svelte and React

#261
post #33

Earlier quoted context omitted.

Not to mention terms that do come from a general programming paradigm, but have a very narrow practical / framework-specific use within frontend dev that makes it even harder for beginners (e.g. "thunk" might be a general term, but I bet most people googling it are just trying to get some Redux tutorial to work, and will end up going down dozens of rabbit holes trying to understand the general concept) I really hate…

React's hooks (and some JSX style things in general) are quite pernicious there because they essentially break JS: you can't use them inside an `if` or a `for` or a `while`, or even within another function. You're no longer writing Javascript, you're writing a restricted subset to avoid undefined behaviour. That alone is a concern, because any junior programmer getting an introduction through React is going to get a…

I decided that react was going down since the introduction of hooks. Before that I was using higher order component (hoc) perfectly fine and there was even libraries like recompose/recompact that made HOCs more convenient. They're really just functions (no magic, not like quote unquote) and they don't invite devs to convert everything into them and break portability/separation of concerns like hooks do. They're also highly composable (there are no such thing as rules of HOCs), you can pass HOCs as params or put them in conditional code branch or whatever you feel like.

Re: Comparing Svelte and React

#262
post #207
post #84

Earlier quoted context omitted.

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.)

Testing-library uses jsdom across the board, as far as I know. It might support running in a full browser too but I haven’t used it that way.

For end-to-end tests with a real browser, Cypress is a good option.

Re: Comparing Svelte and React

#263

Earlier quoted context omitted.

React, Redux, Jest, and it’s ilk always came off to me as a way for Facebook to remain relevant through tech-debt and lock-in.

FWIW, Redux has _never_ been a Facebook project. Yes, both of the creators now work on the React team (Dan Abramov and Andrew Clark), but it's always been an independent OSS project, and is currently maintained by myself and Tim Dorr. As far as I know, FB barely even uses Redux at all internally, and that only in isolated particular teams that chose it themselves. My understanding is that they mostly use Relay for th…

My bad, I didn't mean to include Redux then.

My commentary is more directed at React and Jest (as I try to steer away from that ecosystem, even though it's ideas aren't all bad):

- As GP indicates, React has had multiple API implementations to solve similar problems, feature bloat, leading to opinionated and differing best practices, mixed in with Junior devs can be a nightmare

- With Jest, I find the entire thing as a very aggressive wrapper and very tied to React itself, features like unit test `snapshots` are developer slack-off bait and have the benefit of further entrenching itself into the repository, arguably an e2e test would validate the same thing

Re: Comparing Svelte and React

#264
post #235

Earlier quoted context omitted.

React, Redux, Jest, and it’s ilk always came off to me as a way for Facebook to remain relevant through tech-debt and lock-in.

Doesn't make sense, there is nothing that benefits facebook by "dominating" a tech niche. They dont profit off of development platforms (android and .NET) like google and microsoft

See my other reply in this thread for clarity.

Re: Comparing Svelte and React

#266

Earlier quoted context omitted.

Novel - not, in my opinion. How to do GUI is known from 1970-ties. Today's single page apolication frameworks slowly re-discover the wheel. It is funny to observe.

The very important difference is that we do distributed systems now (admitted, X originally was also distributed, but only the drawing/events parts, not on the data level). A SPA is a distributed system, with all its drawbacks & pitfalls. If you ever did VB development in the 90s, you will know how easy it was to get a basic app running with those fancy Drag'n'Drop RAD tools. But there was no networking, everything w…

There absolutely was a remote part to most VB6 apps. Usually they fetched data from some MS flavour of a RDBMS. Of course they were desktop apps and had to be installed individually but this “webify everything” mania seems to have smothered all dev productivity and experience on its altar.

Re: Comparing Svelte and React

#267

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…

IMO, Svelte’s biggest issue is it didn’t come out of FAANG.

Neither did Vue, or Django, or Rails or dozens of other successful and widely adopted technologies. Svelte's issue is probably that it came out a little too late: companies have adopted React, Vue or Angular, and have sufficient inertia (existing codebases and hard-won experience) that there is little incentive to switch just for a slightly nicer syntax or state management model.

Re: Comparing Svelte and React

#268
post #55
post #17

Earlier quoted context omitted.

They are the same. It's a matter of style. For that matter, you could also write: onMount(listenForAuthChanges) which is technically simpler -- you're not constructing a new anonymous function. But if you wanted to extend the code (to say, add a console.log), you'd need to do the top version, which already has the braces. It's up to your judgment of what's clearer and likely to be more maintainable.

That should work in the provided example, but in general `fn(cb)` is different: you lose the implied `this` binding unless you do `cb.bind(something)` beforehand. There's also some unexpected trouble due to potential extra parameters. Consider the output of ['1', '2', '3'].map(parseInt) gives: [1, NaN, NaN] So yea, fn(() => cb()) is the same as fn(() => {return cb()}) – just syntactic sugar when the anonymous functio…

I consider myself a pretty advanced JS developer, and I still don't understand how "this" works in JS. I avoid using it whenever I can.

Re: Comparing Svelte and React

#269

I wrote my first decent size Svelte app (with a Rails API app backend) last year: https://www.listenaddict.com/ Of course, what you see is just a tip of the iceberg, having implemented a nice admin and moderator dashboard, keyboard shortcuts, animations, 12 different color themes (in light and dark mode), and more. Svelte just made it all so easy to do. Having done a good bit of React and Angular professionally, and…

Your site is brilliant and works really well. I’m also going to check out your YouTube channel.

Re: Comparing Svelte and React

#270
post #227

Earlier quoted context omitted.

We specifically recommend using our official Redux Toolkit package, rather than `typesafe-actions`. RTK is already written in TS and designed for a solid TS usage experience: https://redux-toolkit.js.org

Redux Toolkit is great and removes most of the usual Redux boilerplate which seems to be the most often used argument against Redux. Additionally, I usually use a function which uses createEntityAdapter, createSlice and createAsyncThunk methods to create Ducks bundles for each REST API resource automatically. As a result I get all async action creators, reducers and basic selectors for some REST API resource with a c…

If you like the stuff in RTK so far, I think you're going to like our upcoming "RTK Query" API, which adds a React Query-inspired data fetching abstraction:

https://rtk-query-docs.netlify.app

We're working on finalizing that API and will be merging the functionality and docs back into RTK itself for an upcoming RTK release:

https://github.com/rtk-incubator/rtk-query/issues/175

Post reply on HN