DEV Community

Discussion on: the correct way to fetch data with react hooks

Collapse
 
mykel profile image
Michaël Fischer

Hi @nicomartin ,

Thanks for your great post. I would like to know, with the same sample code, in addition to the error message, how would you display a "Retry" button to fire a new API call?

Collapse
 
nicomartin profile image
Nico Martin • Edited

Hi @mykel ,
Excellent question! In that case I think I would just move the loading logic into a new function that I can then return from the hook as well:
gist.github.com/nico-martin/24de58...

Collapse
 
mykel profile image
Michaël Fischer

Thanks for the answer.