SonicFancy
SonicFancy

Reputation: 309

What is a good way to balance the pros and cons from using Redux?

Of course Redux provides us a very excellent solution for managing the states.

However, it's hard to handle async dispatches and a global state may not be needed for many components in the project.

Is it possible to have a solution can fulfill the basic usage of redux and also handle async problems?

Upvotes: 3

Views: 171

Answers (2)

fkulikov
fkulikov

Reputation: 3199

Please take a look at Redux-Tunk, in case you has not done it yet.

Given it's nice feature of returning the value of the inner function as the result of dispatch invocation and combining this feature with Promises makes it super easy to orchestrate asynchronous state updates.

They have pretty clear explanation of the concept under Compostion section of their doc.

Upvotes: 0

Kulbear
Kulbear

Reputation: 901

You should definitely check Redux-Saga or Redux-Service first.

There are many tutorials and real examples with using Redux-Saga so I'll not talk a lot about it.

Redux-Service is written by one of my colleagues and has been applied to our production environment for a long time. The solution behind is that by combining the idea of Redux-Saga, Redux-Thunk and the generator in JavaScript, Redux-Service offers an experimental way to handle (highly mutable || remote) data source && async logic in Redux.

If you are experienced with backend development framework like Express, you will be familiar with the concept of middlewares. And here you go. The ideas of Express middleware and Redux-Service are pretty similar.

Check more from the document and try to do some mini project with it should be more helpful than words.

Upvotes: 1

Related Questions