-
Notifications
You must be signed in to change notification settings - Fork 25
Support fetching an array of requests. #4
Comments
I don't think it is currently optimized to handle multiple fetch requests simultaneously, but they should be able to dispatch sequentially by just using the hook twice. const x = useFetch('/path/1');
const y = useFetch('/path/2'); If you are unable to dispatch the requests sequentially, let me know, and I'll re-assign this issue as a bug. |
I've also got some requests that I would like to run in parallel. Would be cool that if you pass in an array, it runs them in parallel.
Or something like that. |
It's quite possible to build || request support like @sorahn suggested. For example, rest hooks does this by optionally accepting multiple arguments to one call. Code: https://github.com/coinbase/rest-hooks/blob/master/src/react-integration/hooks/useResource.ts#L54 Feel free to use this as inspiration! |
I'm not opposed to |
Sounds great! |
@BruceL33t Maybe I am misunderstanding your question, but If this is using suspense, isn't the entire point not to advance past the suspended code until it loads so you guarantee that all data is there once it gets to the next part of the code?
|
An oddity about this syntax: how do you specify parameters? useFetch([
'./path.json',
'./path2.json',
]); But now I want RequestInit or lifespan on the fetch requests: useFetch([
'./path.json',
'./path2.json', {}, 60000,
]); Does that mean it's an array of arrays? useFetch([
[ './path.json' ],
[ './path2.json', {}, 60000 ],
]); Is there more intuitive syntax? I am not digging an array of arrays, personally. |
Maybe an array of objects? If you're just doing one thing, then it's That being said, I don't personally mind an array of arrays. Thats how the babel plugins work if you need the extra options, so it's not a totally alien syntax.
You could also just require that it always take an array, that might simplify your code. So even with one it would by something something something less conditionals = good taste |
I'm wondering if maybe it's worth just making a generic 'suspense promise.all' component, so you could pass any number promise arrays to it, and it would just suspense until they're all finished. Then you wouldn't even have to care about it being fetch, or axios or whatever, it just does its thing. |
First of all I'd like to thank your for this awesome package.
But now for a feature request / question.
What if I have a component that needs to do multiple fetch requests before rendering? How would you extend this hook to be able to handle multiple fetch requests?
The text was updated successfully, but these errors were encountered: