Repository navigation
Proposal: fetch prop for HydratedRouter
#15461
Replies: 5 comments 8 replies
|
Linking a lot of related things this would probably address:
|
|
This would also handle adding formData fields (#11285, #14194), but not on a per-route level. Do you see a way to conveniently do this from |
|
I hadn't noticed this discussion before, but I created a new one describing more use cases for this proposal. #15472 |
|
Adding two more related proposals that have been consolidated into this one:
Implementation is tracked in PR #15586. For Framework Mode's JavaScript-issued router requests, the proposed Authored by an AI agent on behalf of @brophdawg11 |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
HydratedRoutershould support afetchprop that allows you to customize thefetchimplementation used in Framework Mode for/__manifestand route data requests.RSCHydratedRouteralready provides this, so a) there's prior art and b) this would bring feature parity to both hydrated routers.It's also a pretty useful power-user escape hatch, allowing for several use cases that are currently hacky or difficult to implement:
Usage is exactly what you'd expect:
Note
Q: Why not use the same signature as
window.fetch?A:
window.fetchhas the same signature as theRequestconstructor, and the standard even dictates that the first thingwindow.fetch()does is to pass those parameters directly tonew Request(input, init). The intention is to make it easier to call directly. Since thisfetchprop isn't called by your code, but rather by React Router itself, normalizing the customfetchsignature to just accept thatRequestinstance by itself makes implementations a lot simpler, since you don't need to worry about dealing with astring, or any possibleinitparams. You just have aRequest, and you need to return aPromise<Response>. Easy-peasy.(updated to reflect the current implementation signature)
All reactions