redux-thunk

What is the difference between redux-thunk and redux-promise?

安稳与你 提交于 2019-11-26 18:46:27
问题 As far as I know and correct me if I am wrong, redux-thunk is a middleware which helps us dispatch async function and debug values in the action itself while when I used redux-promise I couldn't create async functions without implementing my own mechanism as Action throws an exception of dispatching only plain objects. What is the major differences between these two packages? Are there any benefits of using both the packages in a single page react app or sticking to redux-thunk would be

Pros/cons of using redux-saga with ES6 generators vs redux-thunk with ES2017 async/await

我与影子孤独终老i 提交于 2019-11-26 10:04:08
问题 There is a lot of talk about the latest kid in redux town right now, redux-saga/redux-saga. It uses generator functions for listening to/dispatching actions. Before I wrap my head around it, I would like to know the pros/cons of using redux-saga instead of the approach below where I\'m using redux-thunk with async/await. A component might look like this, dispatch actions like usual. import { login } from \'redux/auth\'; class LoginForm extends Component { onClick(e) { e.preventDefault();

Why do we need middleware for async flow in Redux?

不想你离开。 提交于 2019-11-26 03:14:22
问题 According to the docs, \"Without middleware, Redux store only supports synchronous data flow\". I don\'t understand why this is the case. Why can\'t the container component call the async API, and then dispatch the actions? For example, imagine a simple UI: a field and a button. When user pushes the button, the field gets populated with data from a remote server. import * as React from \'react\'; import * as Redux from \'redux\'; import { Provider, connect } from \'react-redux\'; const