useReactHooks icon indicating copy to clipboard operation
useReactHooks copied to clipboard

Only partial Fetch support

Open DaveVanRijn opened this issue 4 years ago • 8 comments
trafficstars

Right now the useFetch hook only supports basic GET requests since it only accepts an URL as parameter. For the hook to be generally useful it should at least support all parameters of the Fetch API, like a config object containing request method, body, headers etc.

Also, the hook expects JSON data as the response which limits the use of the hook. I think the hook should not assume JSON data is being fetched and should just return the Response object instead. Another option could be to use a generic type to determine the return value.

I would love to read other's opinion on this matter.

DaveVanRijn avatar Oct 09 '21 22:10 DaveVanRijn

Hey @DaveVanRijn, nice observation! I totally agree with your point but I guess this hook was supposed to be a simple hook as intended by the creator. One solution that I can think of is to rename this current hook to something like useFetchJSON or useFetchSimple and create a new hook with the name useFetch with all the above functionalities.

@shishirtiwari23 what are your views on this?

@DaveVanRijn would you mind working for the same? I'd assign you for this!

Anuragtech02 avatar Oct 10 '21 04:10 Anuragtech02

@Anuragtech02 and @DaveVanRijn , Yes the enhancements that you suggested are great but the useFetch hook that i created was meant to serve as simple fetch hook as @Anuragtech02 said and yes we should rename the hook to useFetchJSON and create a new hook named useFetch which will serve those enhancements

shishirtiwari23 avatar Oct 10 '21 05:10 shishirtiwari23

@Anuragtech02 and @shishirtiwari23, that would be an excellent solution as well. I'd be happy to create the full useFetch hook!

DaveVanRijn avatar Oct 10 '21 08:10 DaveVanRijn

I’m interested in the full useFetch, as a customer I’d be happy to “use” it and potentially help refine it.

#following

jemccarthy13 avatar Oct 12 '21 10:10 jemccarthy13

@jemccarthy13 Thanks for your support, it means a lot to us and welcome to "useReactHooks" we hope you find something "use"ful here !!

shishirtiwari23 avatar Oct 12 '21 13:10 shishirtiwari23

Hey @DaveVanRijn, hope you're doing well. Any updates on the full useFetch hook?

Anuragtech02 avatar Oct 22 '21 01:10 Anuragtech02

Hi all, I have been a bit ill lately and therefore haven't really had the time to work on the hook. I hope to be able to submit a PR next week!

DaveVanRijn avatar Oct 22 '21 12:10 DaveVanRijn

No worries! Health first, take care :)

Anuragtech02 avatar Oct 23 '21 01:10 Anuragtech02