top | item 21539031

(no title)

arthurdenture | 6 years ago

The alternative would be to write a side effect inside your `render()` function, which is illegal -- it breaks the new Concurrent mode rendering, which can call render() speculatively.

I mean, I see why it's intuitively unappealing to you, but there are perfectly good reasons for the design.

discuss

order

thatswrong0|6 years ago

There are "perfectly good reasons" in the sense that if you artificially limit yourself to using the React component tree to manage routes, yes it makes sense how they arrived at this solution. But after dealing with it for a while, it's just so obviously not the correct approach, and it's crazy to me that it's the defacto router. Cargo culting at its finest. The router could exist outside of or at a higher level than the component tree.

jaquers|6 years ago

It's the defacto router because it has gone through many iterations, has lots of users, is easy to bring into a React app, and doesn't fight w/ React, it works with it. Plus there are a variety of approaches to declaring routes. [0]

I'm not sure I see how obvious it is that a <Redirect/> is wrong. But that's fine, I take your point that it's not particularly intuitive.

I'm of the opinion that routing, in general, is a function of application state - and I like to manage my application state with Redux - so I will often also mix in connected-react-router [1]. This lets you do navigation w/ an imperative API [2].

[0] https://github.com/ReactTraining/react-router/tree/master/pa...

[1] https://github.com/supasate/connected-react-router

[2] https://github.com/supasate/connected-react-router/blob/mast...

Silhouette|6 years ago

The alternative would be to write a side effect inside your `render()` function, which is illegal

That's one alternative. Another is not to try implementing behaviour that has nothing to do with rendering using a rendering library in the first place.

A horrible amount of accidental complexity has been created in the React ecosystem when people have tried to use it like a full framework. If all you have is a hammer, maybe it's time to consider using other tools as well.