Anuragtech02 / useReactHooks

useReactHooks is a curated list of custom react hooks that will benefit people in their daily tasks related to development in react.
MIT License
47 stars 17 forks source link

Only partial Fetch support #7

Open DaveVanRijn opened 2 years ago

DaveVanRijn commented 2 years ago

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.

Anuragtech02 commented 2 years ago

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!

shishirtiwari23 commented 2 years ago

@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

DaveVanRijn commented 2 years ago

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

jemccarthy13 commented 2 years ago

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

following

shishirtiwari23 commented 2 years ago

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

Anuragtech02 commented 2 years ago

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

DaveVanRijn commented 2 years ago

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!

Anuragtech02 commented 2 years ago

No worries! Health first, take care :)