Hi everyone,
Now that onEnter was officially killed with a "The router is not a framework" (see the end of https://github.com/ReactTraining/react-router/issues/3854).
I'd like to know the official way of loading data when entering a page (I'm afraid to say Route).
I'm so lost, but I'm sure I missed something.
Thx (a lot),
Olivier
I have to say, this really really turns me off of React actually. Without a viable router, and without onEnter on the route, it simply is not viable.
Checking to see if a user logs in before the route loads, and loading data asynchronously before a route loads is absolutely tantamount to a modern application. Calling upon us to "hack" a few hundred alternative solutions together, all different, all bug-prone that we essentially have to all start from scratch with.. is a big ask.
@mikepc There are other routers. If you don't like this one, choose another. The great thing about React is nothing is prescribed. You can pick and choose the exact things you want.
@oallouch You can do what you do without a router: Use React's lifecycle methods. This is React Native, but it's the same idea: https://facebook.github.io/react-native/docs/network.html
@timdorr ok. Let's compare with what I do when I use React Native. I start async loading in componentWillMount and I retrieve data from the Redux store using connect. So, the render method is called twice and I have to check if it's the first call (with null or undefined data) and return null. I find it awful, but maybe it's just me.
That's so you have control over what's shown to the user while the data is loading. If it takes a while, you want to show some sort of "Loading..." text or indicator while the data comes back.
@timdorr you just gave me the first viable argument ! :)
The thing is I usually handle loading using a global overlay connected to a Redux state prop that gets changed by my loading code.
Ok, at least it's clear that things won't change for react-router v4. I still hope v3 will get some love and gets updated if it needs to be.
Thx for your time.
I wrote a hoc for dealing with this. https://github.com/Hokkaidosunny/react-router-enter
Most helpful comment
I wrote a hoc for dealing with this. https://github.com/Hokkaidosunny/react-router-enter