1
I started to see React well before learning how to use Redux and always requested in the API using a Fetch
or Axios
in the component itself.
Today I already venture into the world of Redux and come across people making API calls through Redux using frameworks such as redux-saga
and redux-thunk
, creating more complex, larger code with multiple reducers and actions to make a request. Thing I could do with only 4 or 5 lines using fetch
or axios
.
I would like to know if you really should use Redux to make API calls and why I should use it to improve my applications
I thought that too, but I came across a situation that I think would not look very cool with it, for example: I have a component listing, in these components have a button to bookmark the item, when favoriting the item makes a request to API stating that I favored it. , the way I do I put a setState on the component to mark that the item was favorited and only that component was going to update. If I use Redux for this, when I preferred it, all the items in the list would propagate this change because of Redux and I would have to check if the change is for this item
– Danilo Torquato
Danilo, Redux would actually be perfect for this. Only the components you need would hear the change. Since the idea of Redux is a global state, only the item you have bookmarked would look like this. I use Redux with Saga in an application here and it works just like that.
– Carlos Querioz
To understand the benefits of store in the React applications, it would be good to read flux architecture in Portuguese Flux
– Chance