r/javascript • • Jun 28 '18

The exact same app - 1 version made with React, Redux, and React-Router The other made with Vue, Vuex, Vue-Router. Good if you want to see both worlds. User Auth with JWT, note CRUD actions, Koa (Node) backend. MIT license.

https://johndatserakis.github.io/koa-react-notes-web/
459 Upvotes

98 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Jun 28 '18

[deleted]

14

u/spooky___ghost Jun 28 '18

An important point you're missing is that any component that is receiving route information as props will be re-rendered anytime the route changes. On top of the other points mentioned above, opting in to receiving routing props is 100% the correct decision.

In real applications only very few top-level components require any route state. If child components require it they can opt in or you can pass it down through the prop chain. React is all about giving control to the developer you do not want anything to be automatic or implicit.

10

u/[deleted] Jun 28 '18

I think this is exactly the main difference between React and VueJS. Vue requires you to be comfortable with magic and tbf that magic makes 90% of use cases really easy to spin up and develop.

React on the other hand has a small surface area.
It really is basically (state, props) => view.

It's essentially functions all the way down. With React you know exactly when and why a component will re-render at the cost of maybe having to write more code (personally I think it's a small price to pay).

If you're building a few pages and forms you should probably go with Vue, you'll love it and it'll really speed up your development.

If you're building a complex desktop grade application React gives you more power to realize that and the explicitness is a godsend for maintainability.

7

u/[deleted] Jun 28 '18

Why not? I don't want routing available in components that don't need to know about routing.

This lets me be explicit about what I pass in. Why should my say Text component need to know what the current route is or have the ability to change it?

1

u/[deleted] Jun 28 '18

Yeah I agree. For being the defacto rooting library for React, it makes some mind bogglingly strange decisions. Is there another routing library that you prefer?

1

u/[deleted] Jun 28 '18

What are some of the decisions you find strange?

2

u/adstwlearn Jun 29 '18 edited Jun 29 '18

I'll chime in - one more thing I thought was sorta not nice was that there is no more query parameter support in v4 - so I had to download qs (I think it was called) to parse query parameters from the url. Wasn't too happy about that, although not the biggest deal.

2

u/[deleted] Jun 29 '18

Ah yeah I can get behind that. I'm always torn on things like that.

Like I get that there's a perfectly good package out there to do it and I get the argument that different users have different needs but damn it query params are part of a route!

1

u/NoInkling Jun 29 '18

The issue with query strings is that there's no standardised way to parse arrays and nested structures. There are at least 3 syntaxes that see common use, and each parsing library usually only supports one of them.

So react router had to make the tradeoff between convenience and staying unopinionated, and chose the latter, leaving it up to the user to pick their library of choice.

For future reference, there is now a built-in web API URLSearchParams that can parse query strings. It only has basic array support (retrieved via .getAll()), but it can work for simple use cases.

const queryParams = new URLSearchParams(location.search)