-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useRoutes changes the meaning of history.listen #2502
Comments
By the way, the reason this came up is for behaviors and libraries that want to perform some action before the state change. A So, consistency here would be good for the API health and would avoid some confusion for anyone wanting to use |
My vote would be to rename this method to |
Now that 1.0 has shipped is like to take another look at this API. I'm not
|
I don't know if that makes sense. The routing history doesn't just invoke its callback with a different signature. It invokes its callback at a different time - i.e. when all of the async routing stuff is resolved. Even if we merged the routing information onto the location object, I don't see how we could reconcile the question of the different callback invocation time. |
Questions of state aside, the difference is that one is a synchronous operation, while the other is an async operation that has some concept of possible failure. They're quite different. |
One more benefit to using |
One implication is that right now, you can't actually hook into the routing state from outside of the |
@taion Agreed, I'm currently using |
I think we're now having the same discussion in #2614. We're all converging around the same idea, anyway. Let's discuss there. |
In
history
, thelisten
method is for listening to when the location changes. Pretty simple.However, in the router,
useRoutes
changes this definition to whatever it interprets the history state change as. Even worse, it changes the callback signature fromhistory
.There's nothing wrong with that. We should have some sort of event listener for when the router is done doing its routing. However, it makes the API tough to reason around, because if you create a
history
, attach a listener, and then get it back out of context/renderProps, it's now changed the meaning of the function you've just used. Yikes!What would likely make more sense is a separate method for listening to the route changes and leaving
history.listen
unaltered. @taion proposedrouterHistory.listenRoutes
in Discord, so that might be a good name for this.The text was updated successfully, but these errors were encountered: