-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Proposal: Add props argument to willTransitionTo #319
Comments
👍 I was just looking for something like this in our app. |
Along the same vein, it would be nice to have access to the |
@ghempton awesome, thx for the feedback. Agree about the Quick question: is there ever a time when you need to asynchronously set props? i.e. without using |
Seems like an anti-pattern to set props in that hook if the transition is sync– akin to calling |
If the transition is sync, the example I posted doesn't really change much. Just gives you a place to derive props from the params/query. This lets you use React's props validation, which is a nice benefit. var User = React.createClass({
statics: {
willTransitionTo: function (transition, params, query, props) {
props.userID = params.userID;
}
},
// Now we can more clearly declare what props we need.
propTypes: {
userID: React.PropTypes.string.isRequired
}
// ...
}); |
Ah I thought you meant still setting the props async even in a sync transition... In the sync case, however, manipulating props in |
One thing to think about is what is shown during |
@ghempton @rickharrison Yes, calling What I'm asking is if there's a real use case for async props... @rpflorence Any thoughts? |
@mjackson I definitely have a use case for async props. For my particular use case of authentication, it is not as simple as storing that they are logged in. I need to hit my API to check and make sure that their token is valid. Currently, I do this in |
@rickharrison Sounds like you need |
@mjackson I once thought it would be nice to send the route descriptor in, just sending props is probably safer. 👍 |
@mjackson hmm ... I think I'd rather have getAsyncProps allow you to do it sync or asynchronously, otherwise you have two places you're setting the props for a handler. Furthermore, if we do the |
This commit adds the ability for route handlers to load props they need for a given route, optionally asynchronously. Props loaded in this manner cascade from route handlers further up the hierarchy to children, such that props loaded by children take precedence. getRouteProps should return a "hash" of props, the values of which may either be immediate or deferred using promises. As promises resolve, forceUpdate is used to re-render the <Routes>. If no props are promises, the operation is fully synchronous and route handlers will have all the props they need on the initial render. As implemented, this work should satisfy the use cases in #319, #261, #314, #374, and (indirectly) #262.
The whole story around props has changed with 0.11, so I don't think this is necessary any more. Closing for now. |
It would be nice to have a mutable
props
argument inwillTransitionTo
so we can derive props from theparams
and/orquery
that will be passed to the route handler component.The text was updated successfully, but these errors were encountered: