Live data from Hacker News

A Simple Way to Route with Redux

jlongster.com

41–50 of 57 posts

Re: A Simple Way to Route with Redux

#41

I suspect my knowledge is behind the times, but I never understood the appeal of putting stuff like "current thread" in the app state at all. To me, it makes much more sense if the stores (or the single data tree, in the redux case) just contain the flat dumb data, and the URL is used to pick the relevant data that the components need. This way, no state is duplicated anywhere, the stores are dumb, and the URL is lea…

The thing is that a SPA doesn't correspond 1-1 with some REST endpoint -- it's comprised of many calls to different endpoints.

So the SPA's state is different than just "we're now pointing to this resource" -- much more full and complex.

Re: A Simple Way to Route with Redux

#42
Call me old (yes I am!) fashioned, but would it be too much to ask to see some sort of example app using said widget in the post?

This is the second article I've been interested in today here on HN that seems, to me at least, to go on and on extolling the virtues of said framework/extension/etc, and in the end gives absolutely no hint of how to use it.

Yes yes I know...farts like me are behind the curve/too slow/fat/old/stupid etc to understand all this modernity, but really, is it too much to ask for a small example of the Greatness?

Re: A Simple Way to Route with Redux

#44
post #42

Call me old (yes I am!) fashioned, but would it be too much to ask to see some sort of example app using said widget in the post? This is the second article I've been interested in today here on HN that seems, to me at least, to go on and on extolling the virtues of said framework/extension/etc, and in the end gives absolutely no hint of how to use it. Yes yes I know...farts like me are behind the curve/too slow/fat/…

Very fair point, however...

...in this case, it's not a widget, but a routing library. Actually a slightly nicer wrapping library around the same base routing library used by basically every React project, which means that for the user, it'll look exactly like every project that doesn't use it too. The only thing to "see" is basically the API docs.

(That being said, maybe that could be made clearer in the blog post...?)

Re: A Simple Way to Route with Redux

#46
post #44
post #42

Call me old (yes I am!) fashioned, but would it be too much to ask to see some sort of example app using said widget in the post? This is the second article I've been interested in today here on HN that seems, to me at least, to go on and on extolling the virtues of said framework/extension/etc, and in the end gives absolutely no hint of how to use it. Yes yes I know...farts like me are behind the curve/too slow/fat/…

Very fair point, however... ...in this case, it's not a widget, but a routing library. Actually a slightly nicer wrapping library around the same base routing library used by basically every React project, which means that for the user, it'll look exactly like every project that doesn't use it too. The only thing to "see" is basically the API docs. (That being said, maybe that could be made clearer in the blog post..…

This post was strictly intended for current users of redux and react-router. That could be included yes, but I have limited time and I'd rather publish blog posts rather than languish in my "drafts" folder. I can add a few things to this though.

Re: A Simple Way to Route with Redux

#47
post #37

Earlier quoted context omitted.

`updatePath` is an action creator, and there's a PR to rename it to `pushPath` and add `replacePath`. And you shouldn't access route params outside of a router component anyway. (EDIT: ok, the last statement was a simplification. But generally you don't need to, but you could manually move data into the state if you needed to)

I get that, but still no access to params and the ability to change them is still a boon for me. I often will use stand to store some basic state for deep linking certain views. For example a data grid and the sort or filter options. I was able to very elegantly execute this with redux-router and its full exposure of the entire route object and API pairity to pushState and replaceState

That's great! Keep using redux-router then. I think you'd find that there's another pattern that works too, but there are multiple ways to do it.

Re: A Simple Way to Route with Redux

#48
As someone who's mainly just used react for simple components, when is the right time to think about pulling in redux? I'm getting by with just react, but it seems like at some complexity level everyone recommends a flux library (and mostly redux these days). Is it when you have multiple component trees on the page? When AJAX requests are involved? Or do people familiar with redux just drop it in from the very start even on simple components?

Re: A Simple Way to Route with Redux

#49
post #25

> This is what redux-router attempts to do, but it's very complicated and prone to bugs. redux-router is still in beta, so this isn't entirely fair.

I think the "still in beta" argument doesn't hold up so well. Many projects now stay in more-or-less permanent "beta", just as a sign that they're open to significant changes in the future.

With React libraries in particular, the ecosystem is still evolving so fast it seems relevant to note which are bug-prone, popular, etc, just to try and predict which will still be alive in a year.

Re: A Simple Way to Route with Redux

#50
post #23

So why so we want the URL in the state? What's the use case?

One use case of having URL in the state (from the lib's README: https://github.com/jlongster/redux-simple-router ) is that you can snapshot/serialize the app state, and load it up later and see the same thing. This can be useful for development and debugging. It's also worth mentioning that this lib also provides a really useful action creator- updatePath(). It allows you to navigate from other action creators, for e…

Thanks. updatePath is actually something I've been missing so that's great.
Post reply on HN