Add action
prop to useFetcher for easier use with resource routes
#12447
Replies: 2 comments 2 replies
-
I like the idea, I have never found a case where I use the same fetcher with two different URLs, also in most cases you pass the One possible case would be changing a route param, and in most cases for fetchers I just send the data in the body instead of URL (e.g. instead of If we wanted to solve that case, it could be possible to maybe link by route id, so you do: let fetcher = useFetcher<LikeRoute.ActionData>({ route: "routes/like.$id" }) Then request that param for the URL fetcher.submit(data, { params: { id: 123 } }) That would help link it to the route and not the actual URL, and the router can generate the URL using the params and the route id. But that's more complex, and could be solved anyway with the proposed change by dynamically changing the URL of the hook let fetcher = useFetcher({
action: `/like/${props.id}` // this must create a new fetcher when props.id change
}); |
Beta Was this translation helpful? Give feedback.
-
I think it would make sense to name the param "href", so it could be used for both |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Proposal
Hello fellow Remixers!
I've been using remix for a hot minute and one of the biggest gripes I always had with fetchers is that I can't bind them to a single action/endpoint/resource. I usually create utilities like these across all my remix projects:
The above is a simplified implementation to get the point across but you get the general idea, I want to specify something like this for example:
What I propose is the following API (find the PR below):
Use cases
This is mostly useful when creating resource routes. Here is an example use-case:
Additional consideration
In this fashion, it would also maybe be great if we can specify the method as well, I'd like to hear your opinions on this first though.
Here is the PR that implements it:
#12448
Beta Was this translation helpful? Give feedback.
All reactions