DEV Community


Discussion on: React Custom Hook - useFetch

dastasoft profile image
dastasoft • Edited

Very good article, it's good not to repeat and also isolate the logic of the component.

One tip, for me mixing the load state between a string and a boolean is a bit confusing, I know JS allows you to do this and a non-empty string is truthy but personally I think it's better to keep the same data type throughout the application, especially when you are using it only as a flag not to display content.

The different states you have there are closely related so it might be a good idea to use a useReducer, check this article by Kent C. Dodds I bet it will be useful to improve the hook.

techcheck profile image
Andrew Author

Agreed. I used useReducer on my previous article ( Good call on Kent's article 👌.

Forem Open with the Forem app