-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Link that only updates the query (this.updateQuery
)
#378
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
Comments
WHAT. YOU DELETED MY WORK? UNACCEPTABLE |
it broke stuff and we were so young |
ARMISTICE BREACHED. LAUNCH THE KVO9000 |
hahahahaha, I am actually laughing out loud. |
I think the minimum API we need here is:
|
now that we have |
right, so with getActiveQuery you could mixin +1 to |
you don't even need Edit: oh, right. you're talking about further down the component hierarchy. Got it now :) |
so question:
but if i do:
I am not guaranteed that my className or the "this column is being sorted descending" text will stay up to date right? Because in the first, since I was getting the query in this.props, I knew that render would be re-run if the query string changed. But in the latter, since I am not getting it passed in as a prop, it won't cause a re-render right? Or is that fact that a re-render was called on a parent good enough to also ensure that my so if you want to re-render whenever the url query string changes, you still need to pass this.props.query all the way down right? |
actually, further up. A persistent toolbar has a preview button that needs the query params from a deeply nested route to know what to preview. |
Hi, friends! I'm feeling the pain right now of building a whole link just to set a query string. Has this ticket taken a back seat? |
Welp, I don't really know what I'm doing, but here's a pull request! Feel free to tell me that I don't know what I'm doing! 🐫 🎆 🍃 |
It's often desirable to transition to a new state changing only a single part of the URL. This is currently cumbersome as Router.transitionTo and Router.replaceWith both require the full state of the new URL. Router#transitionToMixin and Router#replaceWithMixin are identical to their non-Mixin siblings, however, they use the current router state, augmenting it with the provided values. These new methods are also exposed on the Navigation mixin. For example using the current Navigation and State mixins: // before var query = this.getQuery(); query.sortDir = 'desc'; this.replaceWith( this.getPathname(), this.getParams(), query ); // after this.replaceWithMixin(null, null, { sortDir: 'desc' }); Issue: remix-run#378
Earlier @mjackson said
I have the case where I'm using a <Input type="select" value={this.props.query.groupBy} onChange={this.handleGroupBy}>
<option value="category">View by Category</option>
<option value="date">View by Date</option>
</Input> and then in my handler I do: handleGroupBy(ev) {
// ...
this.context.router.replaceWith(this.context.router.getCurrentPathname(),
this.props.params, {groupBy: value});
} It seems like a lot of code just to update the query as opposed to this.context.router.setQuery({groupBy: value}); Changing the If there is a better way to do the above which I'm missing please let me know! |
Very often you want a link that only updates one or a few parts of the query or params, having to reconstruct and then mutate the current stuff is a pain (I'll type up some real-world use-cases later, I'm in a bit of a hurry right now).
Perhaps we can do a couple things to
<Link/>
make this awesome:Optional
to
I know, we had this once and @machty is awesome.
If you leave off
to
in a link, it will just use the current route.add
setQuery
andsetParams
These would work like
setState
in a component, namely, it merges the current data with new data.add
replace
optionWould be
false
by default, iftrue
the router will usereplaceWith
instead oftransitionTo
.Use Case
Imagine headers in a sortable table, when you click them, you want to update the query, but not all of it, and you don't actually care what route you're at, you just want to change
sortBy
. Finally, you don't want an entry in the history.WHATCHOOTHINK?
The text was updated successfully, but these errors were encountered: