DEV Community

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

rs_silvaba profile image
Ricardo Santos

Hi, I am new to react. It is really not obvious to me what is the benefit of this.
It just looks a bit harder to read.

Other than not being clear about the component current state what else is the issue? could you point other articles that tackle the same problem? I could not really find anything on why having multiple states is bad or has any drawbacks.

Also how is this different from adding a isLoading and isError prop to the stats state for example?

Thank you.

nicomartin profile image
Nico Martin Author

The benefint is that you decouple logic (fetch) from render view.
I mean it's perfectly fine to call an api right inside your component and write the state-logic there as well. But decoupling makes it cleaner in my oppinion.
Especially if you then need to write unit tests you will benefit from this flexibility.