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?
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.
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.